You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using Winston and the Winston-Loki transport to send logs. I have used this exact solution in another service, and the log format works as intended by sending a JSON string as the message, which can be prettified in a Grafana dashboard. However, for the implementation that doesn't work, Winston seems to be appending an extra JSON object {"level":"info"} to the end of my message, which breaks my ability to prettify the JSON in my dashboards. I have triple-checked my implementation, and both use cases are identical and sending log data in the same sanitized format. Despite this, one implementation continues to append that extra JSON object.
If this is a TypeScript issue, what version of TypeScript are you using?
v5.4.5
If this worked in a previous version of Logform, which was it?
No response
Minimum Working Example
My winston logger is set up like this:
import { createLogger, format } from 'winston';
import LokiTransport from 'winston-loki';
const { combine, timestamp } = format;
const options = {
// I have to set this default log to be debug, or debug registers as an info log
level: 'debug',
format: combine(timestamp(), format.json()),
transports: [
new LokiTransport({
batching: false,
host: 'www.logging-endpoint.com',
json: true,
}),
],
};
const winstonLokiLogger = createLogger(options);
export default winstonLokiLogger;
I am using the logger like this:
// Example log body. The message field is a JSON string
const logBody = {
level: 'info',
message: '{"level":"info","message":{"message":"Message received","environment":"development","logLevel":"info","userId":"123"},"labels":{"level":"info"}}',
labels: {
level: 'info',
}
}
// send log
winstonLokiLogger.log(logBody);
The expected output, and output that works in one my legacy services, is the message field in JSON format.
However, I keep getting an extra JSON object appended to the output and this breaks the prettify feature that grafana offers to expand logs. Notice the extra {"level":"info"} at the end of the message.
Actual output
{"level":"info","message":{"message":"Message received","environment":"development","logLevel":"info","userId":"123"},"labels":{"level":"info"}}, {"level":"info"} <-- this
Additional information
No response
🔎 Search Terms
Format, JSON, level
The text was updated successfully, but these errors were encountered:
kzunino
changed the title
[Bug]: Formatting output sending extra JSON object
[Bug]: Formatting output sending extra JSON object in message: {"level":"info"}
May 17, 2024
The problem
I am using Winston and the Winston-Loki transport to send logs. I have used this exact solution in another service, and the log format works as intended by sending a JSON string as the message, which can be prettified in a Grafana dashboard. However, for the implementation that doesn't work, Winston seems to be appending an extra JSON object {"level":"info"} to the end of my message, which breaks my ability to prettify the JSON in my dashboards. I have triple-checked my implementation, and both use cases are identical and sending log data in the same sanitized format. Despite this, one implementation continues to append that extra JSON object.
This may be related to winstonjs/winston#1775
What version of Logform presents the issue?
v2.6.0
What version of Node are you using?
v20.10.0
If this is a TypeScript issue, what version of TypeScript are you using?
v5.4.5
If this worked in a previous version of Logform, which was it?
No response
Minimum Working Example
My winston logger is set up like this:
I am using the logger like this:
The expected output, and output that works in one my legacy services, is the
message
field in JSON format.However, I keep getting an extra JSON object appended to the output and this breaks the prettify feature that grafana offers to expand logs. Notice the extra
{"level":"info"}
at the end of the message.Additional information
No response
🔎 Search Terms
Format, JSON, level
The text was updated successfully, but these errors were encountered: