我需要一个工作示例,它使用 http 传输将日志发布到服务器上。我可以使用文件传输和控制台传输在文件和控制台上记录消息。我也尝试为http传输做同样的事情,winston clien 的源代码看起来像这样:
var winston = require('winston');
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)(),
new (winston.transports.Http)({ host: 'localhost', port:8080 })
]
});
logger.log('info', 'Hello world');
在运行此代码时,我收到如下错误:
D:\Balwant\Devlopment-Env\LoggingDemo\node_modules\winston\lib\winston\transports\http.js:52
req = (self.ssl ? https : http).request({
^
ReferenceError: self is not defined
at Http._request (D:\Balwant\Devlopment- Env\LoggingDemo\node_modules\winston\lib\winston\transports\http.js:52:10)
at Http.log (D:\Balwant\Devlopment-Env\LoggingDemo\node_modules\winston\lib\winston\transports\http.js:109:8)
at emit (D:\Balwant\Devlopment-Env\LoggingDemo\node_modules\winston\lib\winston\logger.js:175:17)
at D:\Balwant\Devlopment-Env\LoggingDemo\node_modules\winston\node_modules\async\lib\async.js:111:13
at Array.forEach (native)
at _each (D:\Balwant\Devlopment-Env\LoggingDemo\node_modules\winston\node_modules\async\lib\async.js:32:24)
at Object.async.each (D:\Balwant\Devlopment-Env\LoggingDemo\node_modules\winston\node_modules\async\lib\async.js:110:9)
at Logger.log (D:\Balwant\Devlopment-Env\LoggingDemo\node_modules\winston\lib\winston\logger.js:203:9)
at Object.<anonymous> (D:\Balwant\Devlopment-Env\LoggingDemo\logger.js:10:8)
at Module._compile (module.js:456:26)
由于我是 node.js 的新手,我不知道如何处理它。我尝试在谷歌上搜索解决方案,但没有得到任何解决方案。请帮助我。
谢谢