我正在使用 npm @google-cloud/logging-winston 将应用程序日志事件发送到 google stack-driver 日志接收器。 下面是我的代码片段,它在我本地的 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
最佳答案
同样的问题,最后是我看错地方了:
从 Google Cloud Platform 外部(例如您的计算机)登录时,如果您没有提供用于登录的资源,默认情况下库会将日志路由到“全局”资源。
在 Google Cloud Platform 内部执行相同操作时,可以在“GCE VM 实例”类别中找到日志。
关于Node.js @google-cloud/logging-winston 在 GCE 实例中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45466830/