我正在OpenShift内部的一个node.js项目上,该项目将系统日志消息记录到外部TCP Graylog服务器。 我的代码没有引发任何异常,但是我在Graylog上看不到任何日志,如何测试OpenShift和Graylog之间的TCP连通性?
对于日志记录,我使用的是winston-syslog模块,并且我将其设置如下:
let options = {
protocol: config.getGraylogProtocol(), //tcp4
host: config.getGraylogHost(), //without "https://", is that ok?
port: config.getGraylogPort(),
app_name: config.getAppName()
}
let syslogTransport = new winston.transports.Syslog(options);
然后将这种传输方式添加到Winston记录器中。
我已经尝试(出于调试目的)将纯文本从这样的TCP客户端发送到Graylog:
let net = require("net");
let client = new net.Socket();
client.connect(config.getGraylogPort(), config.getGraylogHost(), () => {
console.log("CONNECTION WITH GRAYLOG ESTABLISHED"); // this executes!
client.write("hi graylog"); // but I can't see neither this on graylog
client.end("bye graylog"); // nor this
});
client.on("data", data => {
console.log("RECEIVED: " + data); //this doesn't executes
client.destroy();
});
client.on('error', () => {
console.log("TCP CONNECTION CLOSED"); //this doesn't executes
})
client.on('close', err => {
console.log("ERROR ON TCP: " + err); //this doesn't executes
})
此代码块被try-catch块包围,但引发了任何异常。