Skip to content

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

Open
@scooper91

Description

@scooper91

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!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions