【问题标题】:Custom Runtime node.js - Can't see my custom logs in Google App Engine自定义运行时 node.js - 在 Google App Engine 中看不到我的自定义日志
【发布时间】:2015-06-13 16:18:48
【问题描述】:

我们正在使用 Google App Engine 自定义运行时为我们的移动应用程序运行我们的 Node.js 服务器端代码。

HTTP 请求日志记录工作正常,但我们的自定义日志出现问题。

我们使用 winston 和 log4js 作为日志框架,将应用程序特定的日志记录到日志文件中。

在本地运行服务器一切正常,但在 GAE 上找不到日志文件。

我们在GAE中没有找到很多关于Node.js Logging的信息,App Engine需要什么特殊配置吗?

是否可以在不连接服务器的情况下访问海关日志?

【问题讨论】:

    标签: javascript node.js google-app-engine logging


    【解决方案1】:

    您可能已经解决了这个问题,但以防其他人需要它。

    https://cloud.google.com/appengine/articles/logging 中的 Cloud Logging 文档所述

    "Cloud Logging and Managed VMs apps
    Applications using App Engine Managed VMs should write custom log files to the VM's log directory at /var/log/app_engine/custom_logs. 
    These files are automatically collected and made available in the Logs Viewer. 
    Custom log files must have the suffix .log or .log.json. If the suffix is .log.json, the logs must be in JSON format with one JSON object per line. 
    If the suffix is .log, log entries are treated as plain text."
    

    您必须将日志文件输出到文件夹 /var/log/app_engine/

    仅当输出文件命名为 /var/log/app_engine/app.log 时,它才对我有用。我尝试使用 .json 扩展名时没有工作,我认为这是一个错误,因为 Cloud Logging 服务仍处于测试阶段。

    问候。

    【讨论】:

      【解决方案2】:

      我建议使用 papertrail 从谷歌云记录日志。 您可以将它与 winston-papertrail npm 模块一起使用。

      这是使它工作的配置。

      1. https://papertrailapp.com 上创建帐户,您将获得主机 和端口来创建温斯顿传输。

      2. 使用 winston-papertrail 模块为 papertrail 创建 winston 传输。

        import winston from 'winston';
        import expressWinston from 'express-winston';
        //
        // Requiring `winston-papertrail` will expose
        // `winston.transports.Papertrail`
        //
        require('winston-papertrail').Papertrail;
        // create winston transport for Papertrail
        var winstonPapertrail = new winston.transports.Papertrail({
          host: 'logsX.papertrailapp.com',
          port: XXXXX
        });
        
      3. 将传输附加到快递服务器以进行请求记录

        app.use(expressWinston.logger({
          transports: [winstonPapertrail],
          meta: true, // optional: control whether you want to log the meta data about the request (default to true)
          msg: "HTTP {{req.method}} {{req.url}}", // optional: customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}"
          expressFormat: true, // Use the default Express/morgan request formatting. Enabling this will override any msg if true. Will only output colors with colorize set to true
          colorize: true, // Color the text and status code, using the Express/morgan color palette (text: gray, status: default green, 3XX cyan, 4XX yellow, 5XX red).
          ignoreRoute: function (req, res) { return false; } // optional: allows to skip some log messages based on request and/or response
        }));
        

      您还可以使用winstonPapertrail.log('info', 'Any info you want to send to papertrail logs'); 进行自定义日志记录。

      查看https://github.com/kenperkins/winston-papertrail了解更多详情。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-08-01
        • 1970-01-01
        • 2017-04-08
        • 1970-01-01
        • 1970-01-01
        • 2012-06-10
        • 1970-01-01
        相关资源
        最近更新 更多