mirror of
https://github.com/pockethost/pockethost.git
synced 2025-11-24 14:35:49 +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)}`)
|
throw new Error(`Fatal error: ${stringify(args)}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const create = (s: string, configOverride?: Partial<LoggerConfig>) =>
|
const create = (name: string, configOverride?: Partial<LoggerConfig>) =>
|
||||||
createLogger({
|
createLogger({
|
||||||
..._config,
|
..._config,
|
||||||
...configOverride,
|
...configOverride,
|
||||||
pfx: [..._config.pfx, s],
|
pfx: [..._config.pfx, name],
|
||||||
})
|
})
|
||||||
|
|
||||||
const breadcrumb = (s: string) => {
|
const breadcrumb = (s: string | object) => {
|
||||||
|
if (typeof s === 'string') {
|
||||||
pfx.push(s)
|
pfx.push(s)
|
||||||
|
} else {
|
||||||
|
Object.entries(s).forEach(([k, v]) => pfx.push(`${k}: ${v}`))
|
||||||
|
}
|
||||||
return api
|
return api
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compatibility func
|
// Compatibility func
|
||||||
const child = (extra: any) => create(stringify(extra))
|
const child = (name: string) => create(name)
|
||||||
|
|
||||||
const api = {
|
const api = {
|
||||||
raw,
|
raw,
|
||||||
@ -159,6 +163,8 @@ export const createLogger = (config: Partial<LoggerConfig>) => {
|
|||||||
return api
|
return api
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type LoggerServiceApi = ReturnType<typeof createLogger>
|
||||||
|
|
||||||
export const LoggerService = mkSingleton((config: Partial<LoggerConfig> = {}) =>
|
export const LoggerService = mkSingleton((config: Partial<LoggerConfig> = {}) =>
|
||||||
createLogger(config),
|
createLogger(config),
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user