File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -252,6 +252,39 @@ export class CustomLogger<LogObj> extends BaseLogger<LogObj> {
252252}
253253```
254254
255+ ### Sub-logger
256+
257+ Each ` tslog ` -Logger instance can create sub-loggers and bequeath its settings to a child.
258+ It is also possible to overwrite the ` LogObj ` when creating a child.<br >
259+ Sub-loggers are a powerful feature when building a modular application and due to its inheritance make it easy to configure the entire application.
260+
261+ Use ` getSubLogger() ` to create a child logger based on the current instance.
262+
263+
264+ ** Example:**
265+
266+ ``` typescript
267+ const mainLogger = new Logger ({ type: " pretty" , name: " MainLogger" });
268+ mainLogger .silly (" foo bar" );
269+
270+ const firstSubLogger = mainLogger .getSubLogger ({ name: " FirstSubLogger" });
271+ firstSubLogger .silly (" foo bar 1" );
272+ ```
273+
274+ #### Sub-logger with ` LogObj `
275+ You can also overwrite the ` LogObj ` (s. below), when you create a sub-logger:
276+
277+
278+ ``` typescript
279+ const mainLogObj = { main: true , sub: false };
280+ const mainLogger = new Logger ({ type: " pretty" , name: " MainLogger" }, mainLogObj );
281+ mainLogger .silly (" foo bar" );
282+
283+ const subLogObj = { main: false , sub: true };
284+ const firstSubLogger = mainLogger .getSubLogger ({ name: " FirstSubLogger" }, subLogObj );
285+ firstSubLogger .silly (" foo bar 1" );
286+ ```
287+
255288### Settings
256289` tslog ` is highly customizable and pretty much every aspect can be either configured or overwritten.
257290A ` settings ` object is the first parameter passed to the ` tslog ` constructor:
Original file line number Diff line number Diff line change @@ -252,6 +252,39 @@ export class CustomLogger<LogObj> extends BaseLogger<LogObj> {
252252}
253253```
254254
255+ ### Sub-logger
256+
257+ Each ` tslog ` -Logger instance can create sub-loggers and bequeath its settings to a child.
258+ It is also possible to overwrite the ` LogObj ` when creating a child.<br >
259+ Sub-loggers are a powerful feature when building a modular application and due to its inheritance make it easy to configure the entire application.
260+
261+ Use ` getSubLogger() ` to create a child logger based on the current instance.
262+
263+
264+ ** Example:**
265+
266+ ``` typescript
267+ const mainLogger = new Logger ({ type: " pretty" , name: " MainLogger" });
268+ mainLogger .silly (" foo bar" );
269+
270+ const firstSubLogger = mainLogger .getSubLogger ({ name: " FirstSubLogger" });
271+ firstSubLogger .silly (" foo bar 1" );
272+ ```
273+
274+ #### Sub-logger with ` LogObj `
275+ You can also overwrite the ` LogObj ` (s. below), when you create a sub-logger:
276+
277+
278+ ``` typescript
279+ const mainLogObj = { main: true , sub: false };
280+ const mainLogger = new Logger ({ type: " pretty" , name: " MainLogger" }, mainLogObj );
281+ mainLogger .silly (" foo bar" );
282+
283+ const subLogObj = { main: false , sub: true };
284+ const firstSubLogger = mainLogger .getSubLogger ({ name: " FirstSubLogger" }, subLogObj );
285+ firstSubLogger .silly (" foo bar 1" );
286+ ```
287+
255288### Settings
256289` tslog ` is highly customizable and pretty much every aspect can be either configured or overwritten.
257290A ` settings ` object is the first parameter passed to the ` tslog ` constructor:
You can’t perform that action at this time.
0 commit comments