winstonjs / winston

A logger for just about everything.
http://github.com/winstonjs/winston
MIT License
22.63k stars 1.8k forks source link

Error in plugin 'gulp-mocha' transport console not attached to this instance #725

Open lifehackett opened 8 years ago

lifehackett commented 8 years ago

We use Winston for logging in various parts of the application. In our gulpfile.js it gets imported in through some dependencies and is causing errors in other gulp tasks.

My Mocha test runner is

gulp.task('test', function () {
  return gulp.src(testSrcFiles)
    .pipe(mocha())
    .on('error', handleError('Mocha'));
});

gulp.task('watchTest', ['testSimple'], () => {
  gulp.watch(testSrcFiles, ['testSimple']);
})

gulp test works fine gulp watchTest works the first time through, but after a change which triggers the watch I get an error Error in plugin 'gulp-mocha' Transport console not attached to this instance

When I remove any imports inside the gulpfile.js with a dependency on Winston logger, it works fine, but I'm not exactly sure how to resolve the issue.

For completeness, here is our implementation on logger

import winston from 'winston';
import props from './properties';

const logger = new winston.Logger({
  transports: [
    new winston.transports.Console({ timestamp: true }),
  ],
});

logger.transports.console.level = props.logLevel || 'info';

export { logger as default };

Thank you for your time.

indexzero commented 8 years ago

I do not believe this is winston related explicitly, but it might have something to do with gulp or ES6 and winston playing nice together. The following works fine on 2.x:

var winston = require('./');
var props = require('./properties');

const logger = new winston.Logger({
  transports: [
    new winston.transports.Console({ timestamp: true }),
  ],
});

console.dir(Object.keys(logger.transports));
logger.transports.console.level = props.logLevel || 'info';

and outputs:

['console']
lifehackett commented 8 years ago

Thanks for your response. When you say 2.x which lib are you referring to? Winston appears to be at 1.1.2

lifehackett commented 8 years ago

Also, I'm not clear on your example. Our usage of Winston logger works fine, it is only in the specific example I mentioned above where the error occurs. It very well maybe, as you said, a conflict between the 3 libraries. I tried switching to gulp-watch and still get the error.

indexzero commented 8 years ago

Going to try to summon @robrich from the gulp side to try to help us triage this.

lifehackett commented 8 years ago

Much appreciated for the pro-activeness. I have also opened a ticket on the gulp-mocha side https://github.com/sindresorhus/gulp-mocha/issues/113. I'll keep you posted on any progress on there end. Please let me know if I can assist in anyway.