@larvit/log 0.1.2 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@larvit/log",
3
- "version": "0.1.2",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
+ "license": "MIT",
5
6
  "packageManager": "yarn@3.2.3",
6
7
  "scripts": {
7
8
  "build": "rm -f index.js index.d.ts index.js.map && tsc && uglifyjs index.js -o index.js",
@@ -9,7 +10,7 @@
9
10
  },
10
11
  "devDependencies": {
11
12
  "@randomgoods/tap-spec": "5.0.2",
12
- "@types/node": "18.7.18",
13
+ "@types/node": "18.7.20",
13
14
  "@types/tape": "4.13.2",
14
15
  "tape": "5.6.1",
15
16
  "ts-node": "10.9.1",
package/yarn.lock CHANGED
@@ -43,7 +43,7 @@ __metadata:
43
43
  resolution: "@larvit/log@workspace:."
44
44
  dependencies:
45
45
  "@randomgoods/tap-spec": 5.0.2
46
- "@types/node": 18.7.18
46
+ "@types/node": 18.7.20
47
47
  "@types/tape": 4.13.2
48
48
  tape: 5.6.1
49
49
  ts-node: 10.9.1
@@ -114,20 +114,13 @@ __metadata:
114
114
  languageName: node
115
115
  linkType: hard
116
116
 
117
- "@types/node@npm:*":
117
+ "@types/node@npm:*, @types/node@npm:18.7.20":
118
118
  version: 18.7.20
119
119
  resolution: "@types/node@npm:18.7.20"
120
120
  checksum: 83905b5528afe8c4e3f5f33de2699e1a12064d0e1b89310b179ab1801fca73157158ecf84c8dac3681afa77026f12440d34c37bc1107ca461da8df0f086b09e9
121
121
  languageName: node
122
122
  linkType: hard
123
123
 
124
- "@types/node@npm:18.7.18":
125
- version: 18.7.18
126
- resolution: "@types/node@npm:18.7.18"
127
- checksum: 8aec61f0f96e2a69ce51f1f40f949ca578bbb4fe05d7c0b8ce3aeeb848e90f755837f17f6ac132ca404d974fe9b2974150ad3b4984fc9dc7c3ceddb10bae0167
128
- languageName: node
129
- linkType: hard
130
-
131
124
  "@types/tape@npm:4.13.2":
132
125
  version: 4.13.2
133
126
  resolution: "@types/tape@npm:4.13.2"
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="sil"}else if(conf.logLevel==="debug"){levelOut="deb"}else if(conf.logLevel==="verbose"){levelOut="ver"}else if(conf.logLevel==="info"){levelOut="inf"}else if(conf.logLevel==="warn"){levelOut="war"}else if(conf.logLevel==="error"){levelOut="err"}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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