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

后端 未结 2 2016
[愿得一人]
[愿得一人] 2021-01-20 10:14

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

2条回答
  •  Happy的楠姐
    2021-01-20 11:14

    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. 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.

提交回复
热议问题