mirror of
https://github.com/pockethost/pockethost.git
synced 2025-03-30 15:08:30 +00:00
improve log typings
This commit is contained in:
parent
6be202ba26
commit
7f0ba21af5
5
.changeset/tame-needles-play.md
Normal file
5
.changeset/tame-needles-play.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'pockethost': patch
|
||||
---
|
||||
|
||||
Internal refactorings
|
@ -123,20 +123,24 @@ export const createLogger = (config: Partial<LoggerConfig>) => {
|
||||
throw new Error(`Fatal error: ${stringify(args)}`)
|
||||
}
|
||||
|
||||
const create = (s: string, configOverride?: Partial<LoggerConfig>) =>
|
||||
const create = (name: string, configOverride?: Partial<LoggerConfig>) =>
|
||||
createLogger({
|
||||
..._config,
|
||||
...configOverride,
|
||||
pfx: [..._config.pfx, s],
|
||||
pfx: [..._config.pfx, name],
|
||||
})
|
||||
|
||||
const breadcrumb = (s: string) => {
|
||||
pfx.push(s)
|
||||
const breadcrumb = (s: string | object) => {
|
||||
if (typeof s === 'string') {
|
||||
pfx.push(s)
|
||||
} else {
|
||||
Object.entries(s).forEach(([k, v]) => pfx.push(`${k}: ${v}`))
|
||||
}
|
||||
return api
|
||||
}
|
||||
|
||||
// Compatibility func
|
||||
const child = (extra: any) => create(stringify(extra))
|
||||
const child = (name: string) => create(name)
|
||||
|
||||
const api = {
|
||||
raw,
|
||||
@ -159,6 +163,8 @@ export const createLogger = (config: Partial<LoggerConfig>) => {
|
||||
return api
|
||||
}
|
||||
|
||||
export type LoggerServiceApi = ReturnType<typeof createLogger>
|
||||
|
||||
export const LoggerService = mkSingleton((config: Partial<LoggerConfig> = {}) =>
|
||||
createLogger(config),
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user