Skip to content

Commit

Permalink
feat: remove fileTransport from consoleLogger (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore authored and fengmk2 committed Aug 11, 2016
1 parent a8507e4 commit bf58f9e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 30 deletions.
14 changes: 0 additions & 14 deletions lib/egg/console_logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const Logger = require('../logger');
const ConsoleTransport = require('../transports/console');
const FileTransport = require('../transports/file');
const utils = require('../utils');

/**
Expand All @@ -13,8 +12,6 @@ class ConsoleLogger extends Logger {
/**
* @constructor
* @param {Object} options
* - {String} [errorFile] - error file
* if specify this file, logger will redirect error log to the file.
* - {String} [encoding] - log string encoding, default is 'utf8'
*/
constructor(options) {
Expand All @@ -24,21 +21,10 @@ class ConsoleLogger extends Logger {
level: this.options.level,
formatter: utils.consoleFormatter,
}));

if (this.options.errorFile) {
const fileTransport = new FileTransport({
file: this.options.errorFile,
level: 'ERROR', // 只输出 error 级别的到文件
encoding: this.options.encoding,
formatter: utils.defaultFormatter,
});
this.set('file', fileTransport);
}
}

get defaults() {
return {
errorFile: '',
encoding: 'utf8',
level: process.env.NODE_ENV === 'production' ? 'INFO' : 'WARN',
};
Expand Down
16 changes: 0 additions & 16 deletions test/lib/egg/console_logger.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const path = require('path');
const fs = require('fs');
const coffee = require('coffee');
const mm = require('mm');
const rimraf = require('rimraf');
Expand Down Expand Up @@ -45,21 +44,6 @@ describe('test/egg/console_logger.test.js', () => {
.end(done);
});

it('error log file print error level log only', done => {
const errorFile = path.join(tmp, 'error.log');
const options = {
errorFile,
};

coffee.fork(consoleLoggerFile, [ JSON.stringify(options) ])
.end(function() {
const content = fs.readFileSync(errorFile, 'utf8');
content.should.containEql('error foo');
content.should.not.containEql('warn foo');
done();
});
});

it('can set level on NODE_ENV = production', done => {
mm(process.env, 'NODE_ENV', 'production');
const options = {
Expand Down

0 comments on commit bf58f9e

Please sign in to comment.