[Bug]: Log message get overwritten by error message when using printf
krishna-unibuddy opened this issue · 3 comments
The problem
To log with custom log format - we are using a custom format
new transports.Console({
level: this.level,
format: format.combine(
format.errors({ stack: true }),
format.timestamp(),
format.printf(localConsoleMessageFormatter),
),
});
The formatter function is as bellow
const localConsoleMessageFormatter = ({
message,
level,
...rest
}: TransformableInfo): string => {
const formattedMessage = StringUtils.addHyphen(message);
const timestamp = ObjectUtils.getValue(rest, 'timestamp');
const service = StringUtils.addSquareBracket(
ObjectUtils.getValue(rest, 'service'),
);
const stack = StringUtils.addHyphen(ObjectUtils.getValue(rest, 'stack'));
const pid = StringUtils.addSquareBracket(ObjectUtils.getValue(rest, 'pid'));
const className = StringUtils.addSquareBracket(
ObjectUtils.getValue(rest, 'className'),
);
return StringUtils.joinString([
timestamp,
level,
pid,
service,
className,
formattedMessage,
stack,
]);
};
When trying to log error with error message :
logger.error("Error while request", error);
In the result how ever value of message
coming in localConsoleMessageFormatter
is the message in Error.
What version of Logform presents the issue?
v2.4.0
What version of Node are you using?
v14.17.0
If this worked in a previous version of Logform, which was it?
No response
Minimum Working Example
No response
Additional information
No response
🔎 Search Terms
printf error
I'm not sure how to parse this report - what exactly was the expected and actual behavior?
Sorry - It was a cache problem. Earlier usage has splat
and I did not rebuild the package properly. Please go ahead and delete the bug.
format.combine(
format.errors({ stack: true }),
format.timestamp(),
format.splat(),
format.printf(localConsoleMessageFormatter),
),
Thanks!
Note: If using this with Winston, you may want to try with Winston@3.7.1 which has some changes to splat/metadata and see if there are any problems there, as the changes in there will likely be re-rolled-out soon.