morgan logger not writing to file
<p>I am trying to set up a production logging environment in my express nodejs application using morgan.</p>

<p>I tried to do it using this documentation <a href="https://github.com/expressjs/morgan#write-logs-to-a-file" rel="nofollow">https://github.com/expressjs/morgan#write-logs-to-a-file</a></p>

<p>My code regarding the logging looks like this:</p>

<pre><code>var express = require('express');
var path = require('path');
var logger = require('morgan');
var FileStreamRotator = require('file-stream-rotator');
var fs = require('fs');
var app = express();

// logging
if (app.get('env') !== 'development') {
  var logDirectory = path.join('/srv/iss', 'log');

  // ensure log directory exists
  fs.existsSync(logDirectory) || fs.mkdirSync(logDirectory);

  var accessLogStream = FileStreamRotator.getStream({
    date_format: 'YYYYMMDD',
    filename: path.join(logDirectory, 'access-%DATE%.log'),
    frequency: 'daily',
    verbose: false
  });

  // setup the logger
  app.use(logger('combined', {stream: accessLogStream}))
}
else {
  app.use(logger('dev'));
}
</code></pre>

<p>When I start the application in development mode everything works fine, but in production mode the access log file is created, but no log messages are sent into the file.</p>