自定义运行时node.js – 在Google App Engine中看不到我的自定义日志

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

HTTP请求logging工作正常,但我们有我们的自定义日志的问题。

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

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

我们没有发现有关Node.js在GAE中login的很多内容,App Engine是否需要特殊configuration?

无需连接到服务器,是否可以访问海关日志?

你可能已经解决了这个问题,但以防万一别人需要它。

https://cloud.google.com/appengine/articles/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扩展名时,我没有工作,我相信这是一个错误,因为云日志logging服务仍处于testing阶段。

问候。

我会build议使用papertraillogin谷歌云。 你可以用winston-papertrail npm模块来使用它。

这是configuration使其工作。

  1. https://papertrailapp.com创build帐户,您将获得主机和端口来创buildWinston传输。

  2. 使用winston-papertrail模块创buildwinston运输papertrail。

     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. 将传输附加到快速服务器以请求logging

     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. Eg "{{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'); 自定义日志logging。

有关更多详细信息,请参阅https://github.com/kenperkins/winston-papertrail