[英]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:几天来,我一直试图让我的 NodeJS 应用程序登录到 syslog,但没有明显的成功:
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.当此代码运行时,我的终端中没有错误(它编译得很好,我在终端输出中看到“Hello, world!”)但我从未在syslog
进程下看到我的 OSX 控制台应用程序中记录的任何内容。
On the other hand I can manually run syslog -s -l ERROR “Hello, world.”
另一方面,我可以手动运行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)我在这里很困惑——我正在运行 OSX Sierra (10.12.6)
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
我可以看到消息/var/log/system.log
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.