chore(pockethost): add namespace() to logger

This commit is contained in:
Ben Allfree 2024-06-28 06:43:38 -07:00
parent 04dc1295b5
commit 114b1d2513
3 changed files with 13 additions and 5 deletions

View File

@ -0,0 +1,5 @@
---
'pockethost': minor
---
Add namespace() export to core Logger service

View File

@ -19,6 +19,7 @@
"getenv",
"gobot",
"goja",
"immer",
"IPCIDR",
"ipcountry",
"jsonifiable",

View File

@ -53,6 +53,12 @@ export const LogLevels = {
[LogLevelName.Abort]: 6,
} as const
export const namespace = (...names: string[]) =>
names
.filter((v) => !!v)
.map((p) => `[${p}]`)
.join(' ')
export const createLogger = (config: Partial<LoggerConfig>) => {
const _config = mergeConfig<LoggerConfig>(
{
@ -67,11 +73,7 @@ export const createLogger = (config: Partial<LoggerConfig>) => {
_config.level = level
}
const _pfx = (s: string) =>
[s, ...pfx]
.filter((v) => !!v)
.map((p) => `[${p}]`)
.join(' ')
const _pfx = (s: string) => namespace(s, ...pfx)
const _log = (levelIn: LogLevelName, ...args: any[]) => {
doLogAction({