2929🤓 ** Stack trace and pretty errors** <br >
3030👨👧👦 ** Sub logger with inheritance** <br >
3131🙊 ** Mask/hide secrets and keys** <br >
32- 📦 ** ESM with tree shaking support** <br >
32+ 📦 ** CJS & ESM with tree shaking support** <br >
3333✍️ ** Well documented and tested** <br >
3434
3535## Example
@@ -49,8 +49,6 @@ Donations help me allocate more time for my open source work.
4949
5050## Install
5151
52- > ❗ ** ` tslog ` is a native ES module.**
53-
5452``` bash
5553npm install tslog
5654```
@@ -93,16 +91,26 @@ npm start
9391
9492** Otherwise:**
9593
96- Node.js with JavaScript:
94+ ESM: Node.js with JavaScript:
9795``` bash
9896node --enable-source-maps --experimental-specifier-resolution=node
9997```
10098
101- Node.js with TypeScript and ` ts-node ` (with ESM support):
99+ CJS: Node.js with JavaScript:
100+ ``` bash
101+ node --enable-source-maps
102+ ```
103+
104+ ESM: Node.js with TypeScript and ` ts-node ` :
102105``` bash
103106node --enable-source-maps --experimental-specifier-resolution=node --no-warnings --loader ts-node/esm
104107```
105108
109+ CJS: Node.js with TypeScript and ` ts-node ` :
110+ ``` bash
111+ node --enable-source-maps --no-warnings --loader ts-node/cjs
112+ ```
113+
106114Browser:
107115``` html
108116<!doctype html>
@@ -252,6 +260,30 @@ A `settings` object is the first parameter passed to the `tslog` constructor:
252260const logger = new Logger <ILogObj >({ /* SETTINGS */ }, defaultLogObject );
253261```
254262
263+ ##### Changing settings at runtime
264+ ` settings ` is a public property and can also be changed on runtime.
265+
266+ Example on changing ` minLevel ` on runtime:
267+
268+ ``` typescript
269+ const logger = new Logger ({
270+ minLevel: 1
271+ });
272+
273+ // visible
274+ logger .log (1 , " level_one" , " LOG1" );
275+ // visible
276+ logger .log (2 , " level_two" , " LOG2" );
277+
278+ // change minLevel to 2
279+ logger .settings .minLevel = 2 ;
280+
281+ // hidden
282+ logger .log (1 , " level_one" , " LOG3" );
283+ // visible
284+ logger .log (2 , " level_two" , " LOG4" );
285+ ```
286+
255287#### Type: pretty, json, hidden
256288
257289- ` pretty ` ** Default setting** prints out a formatted structured "pretty" log entry.
@@ -298,9 +330,9 @@ secondSubLogger.silly("foo bar 2");
298330
299331Output:
300332``` bash
301- 2022-11-17 10:45:47.705 SILLY [/examples/nodejs/index2.ts:51] MainLogger foo bar
302- 2022-11-17 10:45:47.706 SILLY [/examples/nodejs/index2.ts:54] MainLogger:FirstSubLogger foo bar 1
303- 2022-11-17 10:45:47.706 SILLY [/examples/nodejs/index2.ts:57] MainLogger:FirstSubLogger:SecondSubLogger foo bar 2
333+ 2022-11-17 10:45:47.705 SILLY [/examples/nodejs/index2.ts:51 MainLogger] foo bar
334+ 2022-11-17 10:45:47.706 SILLY [/examples/nodejs/index2.ts:54 MainLogger:FirstSubLogger ] foo bar 1
335+ 2022-11-17 10:45:47.706 SILLY [/examples/nodejs/index2.ts:57 MainLogger:FirstSubLogger:SecondSubLogger] foo bar 2
304336```
305337
306338#### minLevel
@@ -356,6 +388,8 @@ Following settings are available for styling:
356388 - ` {{rawIsoStr}} ` : Renders the date and time in ISO format (e.g.: YYYY-MM-DDTHH:mm: ss .SSSZ)
357389 - ` {{logLevelName}} ` : name of the log level
358390 - ` {{name}} ` : optional name of the current logger and his parents (e.g. "ParentLogger: ThisLogger ")
391+ - ` {{nameWithDelimiterPrefix}} ` : optional name of the current logger (s. above) with a delimiter in the beginning
392+ - ` {{nameWithDelimiterSuffix}} ` : optional name of the current logger (s. above) with a delimiter at the end
359393 - ` {{fullFilePath}} ` : a full path starting from ` / ` root
360394 - ` {{filePathWithLine}} ` : a full path below the project path with line number
361395 - ` prettyErrorTemplate ` : template string for error message. Possible placeholders:
@@ -407,6 +441,8 @@ const logger = new Logger({
407441 dateIsoStr: " white" ,
408442 filePathWithLine: " white" ,
409443 name: [" white" , " bold" ],
444+ nameWithDelimiterPrefix: [" white" , " bold" ],
445+ nameWithDelimiterSuffix: [" white" , " bold" ],
410446 errorName: [" bold" , " bgRedBright" , " whiteBright" ],
411447 fileName: [" yellow" ],
412448 },
0 commit comments