简体   繁体   中英

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

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?

You probably have solved this already, but just in case someone else needs it.

As described at Cloud Logging Doc in 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."

You have to output the log file to the folder /var/log/app_engine/

It worked for me only when the output file was named /var/log/app_engine/app.log. I didn't work when I tried with .json extension, I believe it's a bug since the Cloud Logging service is still in Beta.

Regards.

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.

  1. Create account on https://papertrailapp.com and you will get host and port to create winston transport.

  2. 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 }); 
  3. 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. 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 })); 

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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