Express Morgan not writing logs to file or STDOUT

来源:互联网 发布:windows讲述人快捷键 编辑:程序博客网 时间:2024/05/16 03:34

http://stackoverflow.com/questions/35904450/express-morgan-not-writing-logs-to-file-or-stdout


I figured it out- the logging code needed to be located in the app.js file, not in the file that holds the api calls. I knew the logging code needed to be the first piece of middleware, but I didn't realize it needed to be right after the new instance of the server is instantiated.

var express = require('express'),    app = express(),    config = require('./src/config/server.config'),    morgan = require('morgan'),    fs = require('fs'),//api and server    http = require('http'),    server = new http.Server(app); //set up the loggervar accessLogStream = fs.createWriteStream(__dirname + '/access.log', {flags: 'a'})app.use(morgan('combined',  {"stream": accessLogStream}));//load the api calls for the servervar apiRoutes = require('./src/api/calls.js');apiRoutes(app);

0 0