Coder Social home page Coder Social logo

Comments (2)

indexzero avatar indexzero commented on September 27, 2024

Yes. Pass the levels in when you create your logger. See: Using custom logging levels in the winston@3 docs.

const syslogLevelLogger = winston.createLogger({ 
  levels: winston.config.syslog
});

from winston-syslog.

Noirbot avatar Noirbot commented on September 27, 2024

@indexzero That 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));
}

from winston-syslog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.