簡體   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