我正在使用 npm @google-cloud/logging-winston 将应用程序日志事件发送到谷歌堆栈驱动程序日志接收器。下面是我的代码片段,它在我的本地 macbook 中运行良好。当我尝试在 GCE 实例(谷歌云上的 ubuntu 16.10 图像计算实例)中运行它时,它不会将日志事件发送到日志接收器,并且我无法在谷歌云日志仪表板上看到它。任何帮助在这里表示赞赏
///// code start here
const winston = require('winston');
const Logger = winston.Logger;
const Console = winston.transports.Console;
const LoggingWinston = require('@google-cloud/logging-winston');
// Instantiates a Winston Stackdriver Logging client
const loggingWinston = LoggingWinston({
projectId: 'myproject-id',
keyFilename: 'mykey.json',
level: 'info',// log at 'warn' and above ,
labels: { "env": "poc" }
,
logName: "poc-gcl.log"
});
// Create a Winston logger that streams to Stackdriver Logging
// Logs will be written to: "projects/YOUR_PROJECT_ID/logs/winston_log"
const logger = new Logger({
level: 'info', // log at 'info' and above
transports: [
// Log to the console
new Console(),
// And log to Stackdriver Logging
loggingWinston
]
});
// Writes some log entries
logger.info('Node Winston logger initialized.Transport GCL Stakdriver logging',
{ type: "poc", server: "test" });
//code ends here.
在此先感谢-jag