@larvit/log 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +2 -1
- package/index.d.ts +0 -40
- package/index.js +0 -1
- package/index.js.map +0 -1
package/package.json
CHANGED
package/index.d.ts
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
declare type Metadata = {
|
2
|
-
[key: string]: string;
|
3
|
-
};
|
4
|
-
declare type LogShorthand = (msg: string, metadata?: Metadata) => void;
|
5
|
-
interface LogInt {
|
6
|
-
error: LogShorthand;
|
7
|
-
warn: LogShorthand;
|
8
|
-
info: LogShorthand;
|
9
|
-
verbose: LogShorthand;
|
10
|
-
debug: LogShorthand;
|
11
|
-
silly: LogShorthand;
|
12
|
-
}
|
13
|
-
declare type LogLevel = keyof LogInt;
|
14
|
-
declare type EntryFormatterConf = {
|
15
|
-
logLevel: LogLevel;
|
16
|
-
metadata?: Metadata;
|
17
|
-
msg: string;
|
18
|
-
};
|
19
|
-
declare type LogConf = {
|
20
|
-
context?: Metadata;
|
21
|
-
format?: "text" | "json";
|
22
|
-
logLevel?: LogLevel | "none";
|
23
|
-
entryFormatter?: (conf: EntryFormatterConf) => string;
|
24
|
-
stdout?: (msg: string) => void;
|
25
|
-
stderr?: (msg: string) => void;
|
26
|
-
};
|
27
|
-
export declare function msgJsonFormatter(conf: EntryFormatterConf): string;
|
28
|
-
export declare function msgTextFormatter(conf: EntryFormatterConf): string;
|
29
|
-
export declare class Log implements LogInt {
|
30
|
-
#private;
|
31
|
-
context: Metadata;
|
32
|
-
constructor(conf?: LogConf | LogLevel | "none");
|
33
|
-
error(msg: string, metadata?: Metadata): void;
|
34
|
-
warn(msg: string, metadata?: Metadata): void;
|
35
|
-
info(msg: string, metadata?: Metadata): void;
|
36
|
-
verbose(msg: string, metadata?: Metadata): void;
|
37
|
-
debug(msg: string, metadata?: Metadata): void;
|
38
|
-
silly(msg: string, metadata?: Metadata): void;
|
39
|
-
}
|
40
|
-
export {};
|
package/index.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export function msgJsonFormatter(conf){const payload=Object.assign(conf.metadata,{time:(new Date).toISOString(),logLevel:conf.logLevel,msg:conf.msg});return JSON.stringify(payload)}export function msgTextFormatter(conf){let levelOut="";if(conf.logLevel==="silly"){levelOut="[1;37msil[0m"}else if(conf.logLevel==="debug"){levelOut="[1;35mdeb[0m"}else if(conf.logLevel==="verbose"){levelOut="[1;34mver[0m"}else if(conf.logLevel==="info"){levelOut="[1;32minf[0m"}else if(conf.logLevel==="warn"){levelOut="[1;33mwar[0m"}else if(conf.logLevel==="error"){levelOut="[1;31merr[0m"}else{throw new Error(`Invalid conf.logLevel: "${conf.logLevel}"`)}let str=`${(new Date).toISOString().substring(0,19)}Z [${levelOut}] ${conf.msg}`;const metadataStr=JSON.stringify(conf.metadata);if(metadataStr!=="{}"){str+=` ${JSON.stringify(conf.metadata)}`}return str}export class Log{context;#logLevel;#entryFormatter;#stderr;#stdout;constructor(conf){if(conf===undefined){conf={}}else if(typeof conf==="string"){conf={logLevel:conf}}if(conf.logLevel===undefined){conf.logLevel="info"}if(conf.entryFormatter!==undefined){conf.entryFormatter=conf.entryFormatter}else if(conf.format==="json"){conf.entryFormatter=msgJsonFormatter}else{conf.entryFormatter=msgTextFormatter}if(conf.stderr===undefined){conf.stderr=console.error}if(conf.stdout===undefined){conf.stdout=console.log}this.#logLevel=conf.logLevel;this.#entryFormatter=conf.entryFormatter;this.#stderr=conf.stderr;this.#stdout=conf.stdout;this.context=conf.context||{}}error(msg,metadata){if(this.#logLevel==="none")return;this.#stderr(this.#entryFormatter({logLevel:"error",msg:msg,metadata:Object.assign(metadata||{},this.context)}))}warn(msg,metadata){if(["none","error"].includes(this.#logLevel))return;this.#stderr(this.#entryFormatter({logLevel:"warn",msg:msg,metadata:Object.assign(metadata||{},this.context)}))}info(msg,metadata){if(["none","error","warn"].includes(this.#logLevel))return;this.#stdout(this.#entryFormatter({logLevel:"info",msg:msg,metadata:Object.assign(metadata||{},this.context)}))}verbose(msg,metadata){if(["none","error","warn","info"].includes(this.#logLevel))return;this.#stdout(this.#entryFormatter({logLevel:"verbose",msg:msg,metadata:Object.assign(metadata||{},this.context)}))}debug(msg,metadata){if(["none","error","warn","info","verbose"].includes(this.#logLevel))return;this.#stdout(this.#entryFormatter({logLevel:"debug",msg:msg,metadata:Object.assign(metadata||{},this.context)}))}silly(msg,metadata){if(["none","error","warn","info","verbose","debug"].includes(this.#logLevel))return;this.#stdout(this.#entryFormatter({logLevel:"silly",msg:msg,metadata:Object.assign(metadata||{},this.context)}))}}
|
package/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAgCA,MAAM,UAAU,gBAAgB,CAAC,IAAwB;IACxD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE;QAC5C,IAAI,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE;QAChC,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,GAAG,EAAE,IAAI,CAAC,GAAG;KACb,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAwB;IACxD,IAAI,QAAQ,GAAG,EAAE,CAAC;IAElB,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,EAAE;QAC9B,QAAQ,GAAG,sBAAsB,CAAC;KAClC;SAAM,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,EAAE;QACrC,QAAQ,GAAG,sBAAsB,CAAC;KAClC;SAAM,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE;QACvC,QAAQ,GAAG,sBAAsB,CAAC;KAClC;SAAM,IAAI,IAAI,CAAC,QAAQ,KAAK,MAAM,EAAE;QACpC,QAAQ,GAAG,sBAAsB,CAAC;KAClC;SAAM,IAAI,IAAI,CAAC,QAAQ,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