【问题标题】:Node.js @google-cloud/logging-winston not working inside a GCE instanceNode.js @google-cloud/logging-winston 在 GCE 实例中不起作用
【发布时间】:2017-08-02 16:58:22
【问题描述】:

我正在使用 npm @google-cloud/logging-winston 将应用程序日志事件发送到 google 堆栈驱动程序日志接收器。 下面是我的代码 sn-p,它在我的本地 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

【问题讨论】:

  • 看起来您已经完成了this 教程。但为了确认,here 是我们设置 Winston 的文档。如果您已经阅读了文档并且它仍然给您错误,我建议您在issue tracker 中打开一个缺陷报告,其中包含您遇到的错误(如果有的话)。
  • 您发现问题了吗?对我来说 - 在本地工作没有问题。在 GCE 实例(Kubernetes 引擎)上没有错误,但日志没有出现在 Logging(全局日志)中。应用于实例的云平台(所有 API)范围。服务帐户有日志写入器(尝试过日志管理员)@Digil
  • 在我的一生中,从我的桌面或 Cloud Shell 示例执行示例代码时,我根本找不到这些日志条目。他们只是消失了!我希望我找对地方了,但我在 GCP 控制台日志、所有资源和所有日志类型中到处都找过了。太令人沮丧了!

标签: node.js winston google-api-nodejs-client google-cloud-logging


【解决方案1】:

遇到了同样的问题,最后是因为我看错地方了:

  • 从 Google Cloud Platform 外部(例如您的计算机)登录时,如果您没有提供要登录的资源,则库默认将日志路由到“全局”资源。

  • 在 Google Cloud Platform 中执行相同操作时,可以在“GCE VM 实例”类别中找到日志。

【讨论】:

  • 使用 Cloud Run 还会记录到“全局”资源。
  • 您好,您能具体说明一下如何解决这个问题吗?对我来说,在本地运行时,它会挂在那里 2 分钟并抛出错误(来自日志写入 api)。
【解决方案2】:

也许不是答案,但它可能会有所帮助。我在将本地日志发送到 Stackdriver 时也遇到了问题,最后意识到我的服务帐户没有正确的权限。特别是“日志作者”角色。

https://cloud.google.com/iam/docs/granting-roles-to-service-accounts#granting_access_to_a_service_account_for_a_resource

【讨论】:

    猜你喜欢
    • 2020-01-03
    • 1970-01-01
    • 2014-05-24
    • 2013-04-04
    • 2021-09-01
    • 2018-04-17
    • 2021-11-27
    • 1970-01-01
    • 2019-07-18
    相关资源
    最近更新 更多