tslog icon indicating copy to clipboard operation
tslog copied to clipboard

Feature Request: Print objects to console without expanding them.

Open avin-kavish opened this issue 2 years ago • 2 comments

So when we normally log to console using console.log, browsers print the objects in a contracted format, and you can optionally click to expand to inspect the properties of the object.

Can I get the same behavior with tslog? I scanned through the documentation but couldn't figure out whether that was 100% possible.

avin-kavish avatar Sep 15 '23 05:09 avin-kavish

@avin-kavish you can do this pretty easily by overwriting the default behavior of the logger.

const logger = new Logger({
    overwrite: {
      transportFormatted: (logMetaMarkup: string, logArgs: unknown[], logErrors: string[]): void => {
        console.log(...logArgs);
      }
    } 
});

And if you don't want this to be the default behavior you can create a Sub-Logger

const logger = new Logger({ minLevel: 2 });

export const devSubLogger = logger.getSubLogger({ name: "DevSubLogger", minLevel: 2, overwrite: {
    transportFormatted: (logMetaMarkup: string, logArgs: unknown[], logErrors: string[]): void => {
        console.log(...logArgs);
      }
} });

Then use it like this

import logger, { devSubLogger } from './logger.ts';
...
logger.debug(Accounts) // for expanded logs
devSubLogger.debug(Accounts); // for collapsed logs

It's a pretty simple fix, but I still think this should be a standard feature so others won't have to go to the trouble. It'd be nice to have a type: "plain" option to go with the other options (pretty, json, hidden). Happy to work on it if other's think it will be worthwhile.

shakursmith avatar Nov 18 '23 05:11 shakursmith

I am always happy to merge MRs :-)

terehov avatar Nov 18 '23 07:11 terehov