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

Logging an error without additional data still puts a hyphen in the message field #39

Open
scooper91 opened this issue Aug 5, 2022 · 1 comment
Assignees

Comments

@scooper91
Copy link

Version: 2.9.0

We don't always want to add context to an error - sometimes console.error(new Error('bang')) is fine. If you do that, however, it still tries to add the context to the message field, e.g.

const { LoggerAdaptToConsole } = require('console-log-json');
LoggerAdaptToConsole();

console.error(new Error('bang'));

outputs

{"level":"error","message":"  - bang", ...}

With context, it works fine, e.g.

const { LoggerAdaptToConsole } = require('console-log-json');
LoggerAdaptToConsole();

console.error(new Error('bang'), 'context');

outputs

{"level":"error","message":"context  - bang", ...}

If no context is provided, it should leave the message field alone, e.g. {"level":"error","message":"bang", ...}

I believe this should remove that leading -, but there are actually two spaces before the hyphen, so it wouldn't catch it. There are always two spaces before the hyphen, even when there is context.

Thanks!

@hiro5id
Copy link
Owner

hiro5id commented Dec 26, 2022

Thanks so much! I'll take a look. A bit swamped. But, I would gladly take a pull request if I don't get around to this soon enough.

@hiro5id hiro5id self-assigned this Dec 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants