繁体   English   中英

自定义运行时node.js - 无法在Google App Engine中查看我的自定义日志

[英]Custom Runtime node.js - Can't see my custom logs in Google App Engine

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

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

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

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

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

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

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

正如https://cloud.google.com/appengine/articles/logging中的 Cloud Logging Doc所述

"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服务仍处于测试阶段。

问候。

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

这是使其工作的配置。

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

  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. 将传输连接到express服务器以进行请求记录

     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'); 用于自定义日志。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM