Winston not logging events in productions version of a Node.js app hosted on Google Cloud Compute Engine -


i using winston log events in app. when run code node app.js locally, winston logs events fine. when push code server (gcloud preview app deploy app.yaml), or run in production environment locally (gcloud preview app run app.yaml) doesn't log event. locally winston creates general.log , request.log , edits them required, doesn't of in production mode.

here logging.js code

"use strict";  var fs = require('fs'); var path = require('path'); var winston = require('winston'); var expresswinston = require('express-winston');   module.exports = function(logpath) {    // create logging directory if necessary.   if (!fs.existssync(logpath)) {     fs.mkdirsync(logpath);   }     /*     logger capture requests , output them console     request.log.   */   // [start requests]   var requestlogger = expresswinston.logger({     transports: [       new winston.transports.console({         json: false       }),       new winston.transports.file({         filename: path.join(logpath, 'request.log'),       })     ],     expressformat: true   });   // [end requests]     /*     logger capture top-level errors requests ,     output them in error.log   */   // [start errors]   var errorlogger = expresswinston.errorlogger({     transports: [       new winston.transports.console({         json: false       }),       new winston.transports.file({         filename: path.join(logpath, 'error.log'),       })     ]   });   // [end errors]     /*     general logger used .log, .info, etc. outputs logs     console general.log.   */   // [start general]   winston.add(winston.transports.file, {     filename: path.join(logpath, 'general.log')   });   // [end general]     return {     requestlogger: requestlogger,     errorlogger: errorlogger,     error: winston.error,     warn: winston.warn,     info: winston.info,     log: winston.log,     verbose: winston.verbose,     debug: winston.debug,     silly: winston.silly   };  }; 

here sample (unimportant) event logging testing purposes in app.js

var logging = require('./lib/logging')(process.env.log_path || './'); app.use(logging.requestlogger); app.use(logging.errorlogger); logging.info("sample test log"); 

why isn't code working in production mode?

p.s followed steps here set code

https://cloud.google.com/nodejs/getting-started/logging-application-events

your nodejs running in docker container on managed vm google compute engine.

you have ssh managed vm , connect container.

sudo docker ps 

sudo docker ps

this should output 4 containers : gunicorn , nginx proxy, fluentd connector log app engine , npm start node app

sudo docker exec -it <id of container running npm start> bash 

this gives prompt on container, should able see log files there.


note if want see logs on app engine web console (you should place files in folder '/var/log/app_engine/custom_logs/*.log'

app engin web console


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -