-
Notifications
You must be signed in to change notification settings - Fork 186
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
Formatting not working in v3 #189
Comments
I have the same issue. I use this configuration: const expressLogger = expressWinston.logger({
transports: [
consoleTransport
],
meta: false,
expressFormat: true,
colorize: false
}) With Winston 2.x you had to specify, that you don't want json in the transport, but now that is part of the logger: const consoleTransport = new winston.transports.Console()
const logger = winston.createLogger({
transports: [
consoleTransport
],
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
),
levels: config.levels
}) Now all my express lines are in JSON, no matter what I set in the expressWinston's configuration: info: Server started @ 0.0.0.0:3000
{"level":"info","message":"GET / 200 25ms","meta":{}}
{"level":"info","message":"GET /reload/reload.js 304 1ms","meta":{}}
{"level":"info","message":"GET /presetlist 304 10ms","meta":{}} My previous console transport looked like this with Winston 2.x: const consoleTransport = new (winston.transports.Console)({
prettyPrint: true,
colorize: true,
silent: false,
timestamp: true
}) |
The new transports do take configuration objects, but the formatting options are completely gone: https://github.com/winstonjs/winston/blob/HEAD/docs/transports.md#console-transport |
I solved this problem by using const
{ createLogger, transports, format, config } = require('winston'),
expressWinston = require('express-winston')
const
customFormatter = format(customFormatterHandler),
logger = createLogger({
level: 'debug',
levels: config.syslog.levels,
format: format.combine(customFormatter(), format.json()),
transports: [new transports.Console()]
}),
httpLogger = expressWinston.logger({
winstonInstance: logger
}) |
What is the contents of the |
By the way, using the logger with a formatting to the const winston = require('winston')
const expressWinston = require('express-winston')
const config = {
levels: {
info: 0,
warn: 1,
error: 2
},
colors: {
info: 'green',
warn: 'yellow',
error: 'red'
}
}
winston.addColors(config.colors)
const consoleTransport = new winston.transports.Console()
const logger = winston.createLogger({
transports: [
consoleTransport
],
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
),
levels: config.levels
})
const expressLogger = expressWinston.logger({
transports: [
consoleTransport
],
meta: false,
expressFormat: true,
colorize: true,
winstonInstance: logger // The magic!
}) Note: even though I have the colorize formatting option set for the |
Using a |
@DRoet @imdoroshenko @meszaros-lajos-gyorgy #190 is now merged to master. The |
Thanks for the update, will check it! |
thanks! |
@crellison I'm still running into this issue, even with the I'm using the example from the docs verbatim (only with TypeScript), but I'll paste below: import { Request, Response } from 'express';
import expressWinston from 'express-winston';
import winston from 'winston';
expressWinston.requestWhitelist.push('body');
expressWinston.responseWhitelist.push('body');
export default expressWinston.logger({
transports: [
new winston.transports.Console(),
],
format: winston.format.combine(
winston.format.colorize(),
winston.format.json(),
),
meta: true, // optional: control whether you want to log the meta data about the request (default to true)
msg: 'HTTP {{req.method}} {{req.url}}', // optional: customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}"
expressFormat: true, // Use the default Express/morgan request formatting. Enabling this will override any msg if true. Will only output colors with colorize set to true
colorize: false, // Color the text and status code, using the Express/morgan color palette (text: gray, status: default green, 3XX cyan, 4XX yellow, 5XX red).
ignoreRoute: (req: Request, res: Response) => { return false; }, // optional: allows to skip some log messages based on request and/or response
} as any); The output to my console is unformatted, and looks like this (truncated for brevity):
Exporting this as middleware and then passing it into my Express app. Let me know if there is any other information I can provide, until then I think I'll revert to the |
@galenweber Thanks for letting us know. I've run our example locally and experienced the same issue. I think our example code doesn't show off the best starting options. Please try the ...
format: format.combine(
format.colorize(),
format.simple(),
),
... I changed those two things and got the following output to my console |
I have this problem. I'm using winston with fluentd and elasticsearch, so i need the levels to be logged to fluentd without the console log color formatting, but i want them colorized in the console. The format options in the transport dont seem to have any effect, so you can only set a global format setting. If you use the above instance approach then you need to call multiple log commands which doesnt work for this problem. |
Maybe I am missing something, but it seems like the new formatting stuff from winston v3 gets ignored:
Am I doing something wrong here? it seems like most of the readme examples are still for express-winston 2.x
edit: seems like #190 takes care of the
format
being ignoredThe text was updated successfully, but these errors were encountered: