Node.js@google cloud/logging winston在GCE实例中不工作
我正在使用npm@googlecloud/logging winston将应用程序日志事件发送到google堆栈驱动程序日志接收器。 下面是我的代码片段,它在我本地的macbook上运行得非常好。当我尝试在GCE实例(google cloud上的ubuntu 16.10 image compute实例)中运行它时,它不会将日志事件发送到日志接收器,并且我无法在google cloud logging dashboard上看到它。谢谢你的帮助Node.js@google cloud/logging winston在GCE实例中不工作,node.js,winston,google-api-nodejs-client,google-cloud-logging,Node.js,Winston,Google Api Nodejs Client,Google Cloud Logging,我正在使用npm@googlecloud/logging winston将应用程序日志事件发送到google堆栈驱动程序日志接收器。 下面是我的代码片段,它在我本地的macbook上运行得非常好。当我尝试在GCE实例(google cloud上的ubuntu 16.10 image compute实例)中运行它时,它不会将日志事件发送到日志接收器,并且我无法在google cloud logging dashboard上看到它。谢谢你的帮助 ///// code start he
///// 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可能不是答案,但可能会有所帮助。我在向Stackdriver发送本地日志时也遇到了问题,最终意识到我的服务帐户没有正确的权限。特别是“日志编写器”角色
也有同样的问题,最后是因为我看错了地方:
- 当从Google云平台(例如您的计算机)外部登录时,如果您没有提供要登录的资源,默认情况下,库会将日志路由到“全局”资源
- 在谷歌云平台内部执行相同操作时,可以在“GCE VM实例”类别中找到日志