问题描述
我们正在使用Google App Engine自定义运行时为我们的移动应用程序运行Node.js Serverside代码。
HTTP请求记录工作正常,但我们正在我们的定制日志存在问题。
我们使用winston和log4js作为日志记录框架,将特定于应用程序的日志记录记录到日志文件中。
在本地运行服务器一切正常,但在GAE上找不到日志文件。
我们没有发现很多关于Node.js在GAE中登录,App Engine是否需要特殊配置?
是否有可能在没有连接到服务器的情况下访问海关日志?
我会建议使用papertrail for从谷歌云登录。
您可以在winston-papertrail npm模块中使用它。
以下是配置使其可用。
-
在上创建帐户,您将获得主机
和端口以创建winston传输。
使用winston-papertrail模块为papertrail创建winston传输。b / b
从'winston'导入winston;
从'express-winston'导入expressWinston;
//
//要求`winston-papertrail`将暴露
//`winston.transports.Papertrail`
//
require('winston-papertrail' ).Papertrail;
//为Papertrail创建winston传输
var winstonPapertrail = new winston.transports.Papertrail({
host:'logsX.papertrailapp.com',
port:XXXXX
});
-
将传输附加到表达服务器以进行请求记录
app.use(expressWinston.logger({
transports:[winstonPapertrail],
meta:true,//可选:控制是否要记录有关请求的元数据(默认为true)
msg:HTTP {{req.method}} {{req.url}},//可选:自定义默认记录消息,例如{ {res.statusCode}} {{req.method}} {{res.responseTime}} ms {{req.url}}
expressFormat:true,//使用默认的Express / morgan请求格式。将只会输出colorize设置为true的颜色
colorize:true,//使用Express /摩根颜色调色板(文本:灰色,状态:默认绿色, 3XX青色,4XX黄色,5XX红色)
ignoreRoute:function(req,res){return false;} //可选:允许根据请求和/或响应跳过一些日志消息
}) );
您也可以使用 winstonPapertrail.log('info','任何你想发送给papertrail日志的信息');
用于自定义日志记录。
a href =https://github.com/kenperkins/winston-papertrail =nofollow noreferrer> https://github.com/kenperkins/winston-papertrail 了解更多详情。
We are using Google App Engine Custom Runtime to run our Node.js Serverside code for our mobile application.
HTTP Request logging is working fine, but we are having problems with our custom logs.
We are using winston and log4js as logging frameworks to log our application specific loggings to a log file.
Running the server locally everything works fine, but the log File cannot be found on the GAE.
We did not find a lot about Node.js Logging in the GAE, is there any special configuration needed for App Engine?
Is it possible to access customs logs without, connecting to server?
I would suggest to use papertrail for logging from google cloud. You can use it with winston-papertrail npm module.
Here is configuration to make it work.
Create account on https://papertrailapp.com and you will get hostand port to create winston transport.
Create winston transport for papertrail using winston-papertrail module.
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 });
Attach the transport to express server for request 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. 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 }));
you can also use winstonPapertrail.log('info', 'Any info you want to send to papertrail logs');
for custom logging.
see https://github.com/kenperkins/winston-papertrail for more details.
这篇关于自定义运行时node.js - 无法在Google App Engine中看到我的自定义日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!