tslog icon indicating copy to clipboard operation
tslog copied to clipboard

tslog shouldn't modify global util.inspect styles by default

Open ejose19 opened this issue 4 years ago • 1 comments

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:

  1. Create a logger with default options
  2. Use console.log(inspect({ foo: "bar" }, { colors: true }))
  3. 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

ejose19 avatar Jul 02 '21 19:07 ejose19

I agree. I am going to put in some thoughts.

terehov avatar Aug 23 '22 19:08 terehov

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-maps or for TypeScript node --enable-source-maps --experimental-specifier-resolution=node --no-warnings --loader ts-node/esm

terehov avatar Sep 30 '22 14:09 terehov

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

terehov avatar Nov 15 '22 18:11 terehov