Skip to content

Commit 4609a95

Browse files
committed
Add example to README for console instead of STD
1 parent c4e6ead commit 4609a95

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Diff for: README.md

+31
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,37 @@ For `JSON` logs (no formatting happens here):
695695
});
696696
```
697697

698+
##### Example of sending logs to console instead of the standard output.
699+
700+
```typescript
701+
const logger = new Logger({
702+
type: "pretty",
703+
overwrite: {
704+
transportFormatted: (logMetaMarkup, logArgs, logErrors) => {
705+
// Send different log levels to appropriate console methods
706+
const logLevel = logMetaMarkup.trim().split("\t")[1]; // Extract log level from the markup
707+
switch (logLevel) {
708+
case "WARN":
709+
console.warn(logMetaMarkup, ...logArgs, ...logErrors);
710+
break;
711+
case "ERROR":
712+
case "FATAL":
713+
console.error(logMetaMarkup, ...logArgs, ...logErrors);
714+
break;
715+
case "INFO":
716+
console.info(logMetaMarkup, ...logArgs, ...logErrors);
717+
break;
718+
case "DEBUG":
719+
case "TRACE":
720+
case "SILLY":
721+
default:
722+
console.log(logMetaMarkup, ...logArgs, ...logErrors);
723+
break;
724+
},
725+
},
726+
});
727+
```
728+
698729
### Defining and accessing `logObj`
699730
As described in <a href="#life_cycle">"Lifecycle of a log message"</a>, every log message goes through some lifecycle steps and becomes an object representation of the log with the name `logObj`.
700731
A default logObj can be passed to the `tslog` constructor and will be cloned and merged into the log message. This makes `tslog` >= 4 highly configurable and easy to integrate into any 3rd party service.

0 commit comments

Comments
 (0)