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

Winston 3 breaking on syslog levels. #88

Open
Noirbot opened this issue Nov 10, 2017 · 9 comments
Open

Winston 3 breaking on syslog levels. #88

Noirbot opened this issue Nov 10, 2017 · 9 comments

Comments

@Noirbot
Copy link
Contributor

Noirbot commented Nov 10, 2017

Somewhat a follow-on to #87, which was closed.

Setting the syslog log levels with the param on createLogger, as is appropriate for Winston 3 doesn't seem to be working quite as expected. I made a little test program:

const { createLogger, format, transports, config, } = require('winston');
require('winston-syslog').Syslog;

const logger = createLogger({
  levels: config.syslog,
  format: format.simple(),
  transports: [
    new transports.Console(),
    new transports.Syslog({
      type:     '5424',
      protocol: 'unix',
      path:     '/var/run/syslog',
    })
  ]
});

logger.notice(`Current Testing Time is: ${new Date()}`)
logger.error("Here is a test error message")

When I run that with Node 8, Winston 3.0.0-rc1, I get this error:

TypeError: logger.notice is not a function

Which implies that it's not getting the right levels, which seems odd, since winston.config.syslog logs out as:

{ levels:
   { emerg: 0,
     alert: 1,
     crit: 2,
     error: 3,
     warning: 4,
     notice: 5,
     info: 6,
     debug: 7 },
  colors:
   { emerg: 'red',
     alert: 'yellow',
     crit: 'red',
     error: 'red',
     warning: 'red',
     notice: 'yellow',
     info: 'green',
     debug: 'blue' } }

Now, if I swap the Logger constructor to:

  levels: config.syslog.levels,

We get further, but now I get this error:

notice: Current Testing Time is: Tue Nov 07 2017 08:59:07 GMT-0600 (CST) {}
/Users/perry.shuman/Code/temp/log_test/node_modules/winston-syslog/lib/winston-syslog.js:126
    return callback(new Error('Cannot log unknown syslog level: ' + level));
           ^

TypeError: callback is not a function
    at exports.Syslog.Syslog.log (/Users/perry.shuman/Code/temp/log_test/node_modules/winston-syslog/lib/winston-syslog.js:126:12)
    at exports.Syslog.TransportStream._write (/Users/perry.shuman/Code/temp/log_test/node_modules/winston-transport/index.js:88:17)
    at doWrite (_stream_writable.js:387:12)
    at writeOrBuffer (_stream_writable.js:373:5)
    at exports.Syslog.Writable.write (_stream_writable.js:290:11)
    at DerivedLogger.ondata (_stream_readable.js:639:20)
    at emitOne (events.js:121:20)
    at DerivedLogger.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)

Which looks like winston-syslog isn't reading the level that's passed in as a valid level, since you shouldn't be able to get to line 126 without failing this conditional:

if (!~levels.indexOf(level)) {
    return callback(new Error('Cannot log unknown syslog level: ' + level));
}
@arthurakay
Copy link

I have noticed the same thing using Winston v2.4.0.

const winston = require('winston');
require('winston-syslog').Syslog;

const syslogConfig = {host: 'localhost', port: 514};

const logger = new winston.Logger({
    levels: winston.config.syslog.levels,
    transports: [
        new (winston.transports.Console)({
            json: false,
            colorize: true,
            timestamp: true
        }),
        new (winston.transports.Syslog)({
            host: syslogConfig.host,
            port: syslogConfig.port
        })
    ]
});

module.exports = logger;

I get the same error as @Noirbot

return callback(new Error('Cannot log unknown syslog level: ' + info[LEVEL]));

Any update on when there might be a fix for this issue?

@beiwenhuang
Copy link

I still got the same error with winston v3.10.3, [email protected]
return callback(new Error('Cannot log unknown syslog level: ' + info[LEVEL]));
^

TypeError: callback is not a function

Here is my logger.js:
const winston = require('winston');
require('winston-syslog').Syslog;

Any thoughts?
const syslogTransportOptions = {
protocol: 'udp4',
path: '/var/log',
port: '514',
};

const logger = new (winston.Logger)({
transports: [
new (winston.transports.Console),
new winston.transports.Syslog(syslogTransportOptions),
],
});

@knownasilya
Copy link

Had the same issue as above

@MukilanP
Copy link

MukilanP commented Mar 1, 2018

I am getting the same issue. Is anybody having any solution/idea?

@fabiocatalao
Copy link

The same is happening with me.
Do you know any combination of winston/transport/syslog that is working correctly?

@vlastoun
Copy link

vlastoun commented May 7, 2018

Any example how to make correct syslog logger?

@iamdey
Copy link

iamdey commented May 18, 2018

@vlastoun the default values should work.

I'm not experienced with syslog but the following might help.

For info I needed to enable udp in my rsyslog config (debian 9); in ``, uncomment the folllowing lines

# provides UDP syslog reception
module(load="imudp")
input(type="imudp" port="514"

then restart the service : service rsyslog restart
and then logs start to appear in /var/log/syslog

@cjbarth
Copy link
Contributor

cjbarth commented Oct 2, 2019

I can verify this is still a problem. I can reproduce it like such:

winston.loggers.add("default");
const log = winston.loggers.get("default");
log.levels = winston.config.syslog.levels;
log.add(new winston.transports.Console());

log.log("warning", "named warning message");
log.warning("warning message");

Running that code will produce the following:

{"level":"warning","message":"named warning message"}
TypeError: log.warning is not a function
    ...
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Clearly that isn't right since log.log("warning", "message") should be 100% the same as log.warning("message").

@cjbarth
Copy link
Contributor

cjbarth commented Oct 2, 2019

I was able to reproduce this problem without winston-syslog, so this appears to be a winston issue. I've opened this issue there: winstonjs/winston#1711

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

9 participants