title: Adding winston to express app
body: <p>I would like to use <a href="https://www.npmjs.com/package/winston" rel="nofollow noreferrer">winston</a> in my express app.</p>
  
  <p>I have configured winston like the following:</p>
  
  <pre><code>const path = require('path')
  const winston = require('winston')
  
  module.exports = () =&gt; {
    process.on('uncaughtException', err =&gt; winston.error('uncaught exception: ', err))
    process.on('unhandledRejection', (reason, p) =&gt; winston.error('unhandled rejection: ', reason, p))
  
    winston.emitErrs = true
    winston.exitOnError = false
    winston.level = process.env.NODE_ENV === 'production' ? 'info' : 'debug'
    winston.remove(winston.transports.Console)
  
    winston.add(winston.transports.Console, {
      level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
      handleExceptions: true,
      prettyPrint: true,
      humanReadableUnhandledException: false,
      json: false,
      colorize: true,
      timestamp: new Date(),
    })
  
    winston.add(winston.transports.File, {
      level: 'info',
      filename: path.join(__dirname, '../logs/app.log'),
      handleExceptions: true,
      humanReadableUnhandledException: true,
      json: false,
      maxsize: 10242880, // ~10MB
      maxFiles: 3,
      colorize: false,
      timestamp: new Date(),
    })
  }
  </code></pre>
  
  <p>In my express app I want to add winston as a middleware to log the console:</p>
  
  <pre><code>const express = require('express')
  const winston = require("./config/winston")
  const app = express()
  
  //initialize winston
  app.use(winston)
  
  app.get('/', function (req, res) {
    res.send('Hello World!')
  })
  
  //Start Server
  const port = process.env.APP_PORT || 3000
  const host = process.env.APP_HOST || "localhost"
  
  app.listen(port, function() {
    console.log("Listening on " + host + ":" + port)
  })
  </code></pre>
  
  <p>My problem is  that my app does not load and gives me back the following error message:</p>
  
  <pre><code>Error: Transport already attached: file, assign a different name
      at exports.Logger.Logger.add (C:\Users\user\Desktop\Coding Projects\learning_npm_winston\node_modules\winston\lib\winst
  on\logger.js:487:11)
      at Object.winston.(anonymous function) [as add] (C:\Users\user\Desktop\Coding Projects\learning_npm_winston\node_module
  s\winston\lib\winston.js:86:34)
      at module.exports (C:\Users\user\Desktop\Coding Projects\learning_npm_winston\src\t02-loggingToFolder.js:23:11)
      at Layer.handle [as handle_request] (C:\Users\user\Desktop\Coding Projects\learning_npm_winston\node_modules\express\li
  b\router\layer.js:95:5)
      at trim_prefix (C:\Users\user\Desktop\Coding Projects\learning_npm_winston\node_modules\express\lib\router\index.js:317
  :13)
      at C:\Users\user\Desktop\Coding Projects\learning_npm_winston\node_modules\express\lib\router\index.js:284:7
      at Function.process_params (C:\Users\user\Desktop\Coding Projects\learning_npm_winston\node_modules\express\lib\router\
  index.js:335:12)
      at next (C:\Users\user\Desktop\Coding Projects\learning_npm_winston\node_modules\express\lib\router\index.js:275:10)
      at expressInit (C:\Users\user\Desktop\Coding Projects\learning_npm_winston\node_modules\express\lib\middleware\init.js:
  40:5)
      at Layer.handle [as handle_request] (C:\Users\user\Desktop\Coding Projects\learning_npm_winston\node_modules\express\li
  b\router\layer.js:95:5)
  </code></pre>
  
  <p>Any suggestion what I am doing wrong?</p>
  
  <p>I appreciate your replies!</p>