Custom node.js runtime - Can't view my own logs in Google App Engine

We use custom Runtime for Google App Engine apps to run our Node.js server code for our mobile app.

The HTTP request protocol is working fine, but we are having problems with our custom logs.

We use winston and log4js as logging frameworks to log our application specific apps to a log file.

Running the server locally everything works fine, but the log file cannot be found in GAE.

We didn't find much about Node.js Logging into GAE, is there any special configuration needed for App Engine?

Is it possible to access customs journals without connecting to a server?

+2


source to share


2 answers


You probably solved this, but in case someone needs it.

As described in the Cloud Logging Doc at 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 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 should output the log file to / var / log / app _engine / folder

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

Sincerely.

+1


source


I would suggest using papertrail for logging from google cloud. You can use it with the npm winston-papertrail module.

Here is the configuration to get it working.

  • Create an account at https://papertrailapp.com and you will get a host and port to create a winston transport.

  • Create a winston transport for papertrail using the 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 transport for 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.

+1


source







All Articles