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

log level not making it through #78

Open
yitzgold opened this issue Nov 7, 2019 · 1 comment
Open

log level not making it through #78

yitzgold opened this issue Nov 7, 2019 · 1 comment

Comments

@yitzgold
Copy link

yitzgold commented Nov 7, 2019

If you have colorize turned on for the winston logger you will not get log level set correctly

The reason is that the first character is an escape character to make error display in red.
https://github.com/namshi/winston-graylog2/blob/master/lib/winston-graylog2.js#L25

Not sure why you write that formatters can't be set on transport level see below how I did it and now it works!

Here is a sample what will work.

"use strict";

const os = require("os");
const winston = require("winston");
const { format } = winston;
const WinstonGraylog2 = require("winston-graylog2");
const {
  NODE_ENV,
  GRAYLOG_URL,
  GRAYLOG_PORT,
  GRAYLOG_FACILITY_NAME,
  LOG_LEVEL,
} = require("../config/env");

var grayLogOptions = {
  name: "Graylog",
  silent: false,
  level: LOG_LEVEL,
  handleExceptions: false,
  //showLevel: false,
  graylog: {
    servers: [
      {
        host: GRAYLOG_URL,
        port: GRAYLOG_PORT,
      },
    ],
    hostname: os.hostname(),
    facility: GRAYLOG_FACILITY_NAME,
    bufferSize: 1400,
  },
};

const winstonTransports = [];

if (NODE_ENV === "production") {
  winstonTransports.push(new WinstonGraylog2(grayLogOptions));
}

const logger = new winston.createLogger({
  transports: winstonTransports,
  format: format.combine(
    format.errors({ stack: true }), // Handle errors (was automagic in winston@2)
    // new
    format.metadata(),
  ),
});
logger.add(
  new winston.transports.Console({
    format: winston.format.combine(
      format.splat(), // Handle splat (was automagic in winston@2)
      format.timestamp(), // { timestamp: true }
      format.colorize(), // { colorize: true })
      format.simple(), // Default serialization in winston@2
    ),
  }),
);

module.exports = { logger };
@jeremy-j-ackso
Copy link
Contributor

I think it was just assumed that you couldn't set the format at the transport level because the Winston formatting docs don't mention or show it.

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