tslog shouldn't modify global util.inspect styles by default
Describe the bug
Currently, tslog overwrites util.inspect styles by its own:
https://github.com/fullstack-build/tslog/blob/2760b4144691a354126059a9d100a8c3c4879895/src/LoggerWithoutCallSite.ts#L75-L87
https://github.com/fullstack-build/tslog/blob/2760b4144691a354126059a9d100a8c3c4879895/src/LoggerHelper.ts#L136-L144
which will affect other consumers of util.inspect, this shouldn't be enabled by default and instead by provided as an export (ie: CustomHighlightStyles that must be explicitly be used as:
import { Logger, CustomHighlightStyles } from "tslog";
const log = new Logger({ prettyInspectHighlightStyles: CustomHighlightStyles });
To Reproduce Steps to reproduce the behavior:
- Create a logger with default options
- Use
console.log(inspect({ foo: "bar" }, { colors: true })) - Notice how the colors changed implicitly
Expected behavior Global shouldn't be modified implicitly
Screenshots N/A
Additional context
I'm aware util.inspect doesn't provide a way to create a custom inspect function (ie: new Inspect()), so in case this library needs to modify global inspect at least it should be explicitly (and with a docs warning).
Node.js Version 16.3.0
OS incl. Version Archlinux
I agree. I am going to put in some thoughts.
V4 beta is out, and it does not modify the styles any more. Give it a go and let me know if that solves your problem. I'll publish the final version as soon as I have gathered enough feedback.
This is how you can change all styles, even by value: https://github.com/fullstack-build/tslog/blob/v4/tests/Nodejs/9_pretty_Styles.test.ts#L19
-
npm i tslog@next -
and run it with
node --enable-source-mapsor for TypeScriptnode --enable-source-maps --experimental-specifier-resolution=node --no-warnings --loader ts-node/esm
V4 is released now, so I'm going to close this issue. Feel free to open a new one if V4 didn't solve it for you.
Here are the docs: tslog.js.org