yamashita
yamashita

Reputation: 11

output logs into /var/log/syslog

Our legacy system was outputting to /var/log/syslog with posix module without any tuning. But this posix package is no longer available in Node.js v10, we had to adopt other logging module.

We are now trying to use winston module instead of it, and our setting is like below.

this.logger = winston.createLogger({
  levels: winston.config.syslog.levels,
  transports: [
    new winston.transports.Console(),
    new winston.transports.File({
      filename: '/var/log/syslog'
    })
  ]
});

But we can't get any logs in /var/log/syslog, maybe it is due to the permission problem. Does anyone have the best solution for this? What we would like to do is to enable to output logs into /var/log/syslog with ease settings.

I think the best way is to change destination file, if you don't have any better way, just tell 'change the destination file' to me.

Upvotes: 1

Views: 1726

Answers (2)

Shiwa Aki
Shiwa Aki

Reputation: 11

You most probably have indeed a permission problem considering /var/log/syslog is managed by system utilities.

Anyway the fastest solution is to use the npm package winston-syslog, it is pretty easy to configure if you look at the documentation

const winston = require('winston');

//
// Requiring `winston-syslog` will expose
// `winston.transports.Syslog`
//
require('winston-syslog').Syslog;

winston.add(new winston.transports.Syslog(options));

Upvotes: 1

Yaroslav Gaponov
Yaroslav Gaponov

Reputation: 2099

Actually you can output log to console and redirect stdout and stderr streams to files

Upvotes: 0

Related Questions