Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Print objects to console without expanding them. #263

Open
avin-kavish opened this issue Sep 15, 2023 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@avin-kavish
Copy link

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 avin-kavish added the enhancement New feature or request label Sep 15, 2023
@shakursmith
Copy link

@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.

@terehov
Copy link
Contributor

terehov commented Nov 18, 2023

I am always happy to merge MRs :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants