@highoutput/logger
Advanced tools
Comparing version 0.4.1 to 0.5.0
declare type Argument = number | string | Error | object; | ||
declare class Logger { | ||
private tags; | ||
constructor(tags: string | string[]); | ||
constructor(tags?: string | string[]); | ||
tag(tags: string | string[]): Logger; | ||
@@ -6,0 +6,0 @@ log(level: string, ...args: Argument[]): void; |
@@ -13,21 +13,16 @@ "use strict"; | ||
constructor(tags) { | ||
if (tags instanceof Array) { | ||
this.tags = tags; | ||
if (tags) { | ||
this.tags = (tags instanceof Array) ? tags : [tags]; | ||
} | ||
else { | ||
this.tags = [tags]; | ||
} | ||
} | ||
tag(tags) { | ||
return new Logger([ | ||
...this.tags.slice(0), | ||
...(typeof tags === 'string' ? [tags] : tags), | ||
...(this.tags || []).slice(0), | ||
...((tags instanceof Array) ? tags : [tags]), | ||
]); | ||
} | ||
log(level, ...args) { | ||
const tags = [...this.tags].join(','); | ||
const scope = `${level}${tags ? `:${tags}` : ''}`; | ||
const logger = loggers.get(scope) || debug_1.default(scope); | ||
if (!loggers.get(scope)) { | ||
loggers.set(scope, logger); | ||
const logger = loggers.get(level) || debug_1.default(level); | ||
if (!loggers.get(level)) { | ||
loggers.set(level, logger); | ||
} | ||
@@ -39,3 +34,6 @@ args | ||
Object.getOwnPropertyNames(item).forEach(property => { | ||
obj[property] = item[property]; | ||
obj[property] = | ||
(typeof item[property] === 'string') ? | ||
item[property].replace(/\n/g, '\\n') : | ||
item[property]; | ||
}); | ||
@@ -45,3 +43,3 @@ return obj; | ||
if (typeof item === 'string') { | ||
return item.replace(/\n/, '\\n'); | ||
return item.replace(/\n/g, '\\n'); | ||
} | ||
@@ -54,6 +52,3 @@ if (typeof item === 'number') { | ||
.map(item => { | ||
if (typeof item === 'object') { | ||
return JSON.stringify(item); | ||
} | ||
return item; | ||
return JSON.stringify(Object.assign(Object.assign({ tags: this.tags }, (process.env.SERVICE_NAME) ? { service: process.env.SERVICE_NAME } : {}), { message: item })); | ||
}) | ||
@@ -60,0 +55,0 @@ .forEach(item => logger(item)); |
{ | ||
"name": "@highoutput/logger", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"main": "build/index.js", | ||
@@ -30,3 +30,3 @@ "dependencies": { | ||
}, | ||
"gitHead": "eab757e77dd61ee8efe339649c347a23c7ad155b" | ||
"gitHead": "9777f311ea6768e63ccd056627bfdab967da59a7" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8956
86
3