arthurakay
arthurakay

Reputation: 5651

NodeJS - Logging Winston out to syslog on OSX

I've been trying to get my NodeJS application logging into syslog for days now with no apparent success:

const winston = require('winston');
require('winston-syslog').Syslog; // eslint-disable-line

const env = process.env.NODE_ENV;
let syslogConfig = {
    "host": "localhost",
    "port": 514,
    "protocol": "unix",
    "path": "/var/run/syslog"
};

const logger = new winston.Logger({
    levels: winston.config.syslog.levels,
    colors: winston.config.syslog.colors
});

logger.add(winston.transports.Syslog, syslogConfig);

logger.add(winston.transports.Console, {
    json: false,
    colorize: true,
    timestamp: true
});

logger.error('Hello, world!');

module.exports = logger;

When this code runs I get no errors in my terminal (it compiles just fine, and I see "Hello, world!" in my terminal output) but I never see anything logged in my OSX Console app under syslog process.

On the other hand I can manually run syslog -s -l ERROR “Hello, world.” in my terminal and it shows up in Console app.

I'm pretty stumped here -- I'm running OSX Sierra (10.12.6)

Upvotes: 3

Views: 1458

Answers (1)

Zitoun
Zitoun

Reputation: 720

It's been years since this message. I finally got something working so thought I should share:

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

// Logger creation
const logger = winston.createLogger({
  levels: winston.config.syslog.levels,
})

// Console feedback
logger.add(
  new winston.transports.Console({
    name: 'consoleLogs'
  })
)

// Sending to syslog
logger.add(
  new winston.transports.Syslog({
    protocol: 'unix',
    path: '/var/run/syslog'
  })
)

// Test message
logger.alert('Hello world!!')

I can see the message /var/log/system.log

Upvotes: 1

Related Questions