Skip to content

Commit a89fdaf

Browse files
akxpiotr-oles
authored andcommitted
fix: log everything to stderr, not stdout (#321)
1 parent 4e8c6f9 commit a89fdaf

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/defaultLogger.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// tslint:disable:no-console
2+
import { Logger } from '.';
3+
4+
const defaultLogger: Logger = {
5+
// since `console.warn` is an alias to `console.error`,
6+
// and `console.error` is really only a `console.info` for stderr
7+
// instead of stdout, these are all equivalent by default.
8+
error: console.error,
9+
warn: console.error,
10+
info: console.error
11+
};
12+
13+
export default defaultLogger;

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { createDefaultFormatter } from './formatter/defaultFormatter';
1616
import { createCodeframeFormatter } from './formatter/codeframeFormatter';
1717
import { fileExistsSync } from './FsHelper';
1818
import { Message } from './Message';
19+
import defaultLogger from './defaultLogger';
1920

2021
import {
2122
getForkTsCheckerWebpackPluginHooks,
@@ -164,7 +165,7 @@ class ForkTsCheckerWebpackPlugin {
164165
this.ignoreLints = options.ignoreLints || [];
165166
this.ignoreLintWarnings = options.ignoreLintWarnings === true;
166167
this.reportFiles = options.reportFiles || [];
167-
this.logger = options.logger || console;
168+
this.logger = options.logger || defaultLogger;
168169
this.silent = options.silent === true; // default false
169170
this.async = options.async !== false; // default true
170171
this.checkSyntacticErrors = options.checkSyntacticErrors === true; // default false

test/integration/general.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import fs from 'fs';
33
import path from 'path';
44
import ForkTsCheckerWebpackPlugin from '../../lib/index';
5+
import defaultLogger from '../../lib/defaultLogger';
56
import * as helpers from './helpers';
67
import { cloneDeep } from 'lodash';
78
import unixify from 'unixify';
@@ -49,10 +50,10 @@ describe.each([[true], [false]])(
4950
expect(plugin['tslint']).toBe(true);
5051
});
5152

52-
it('should set logger to console by default', () => {
53+
it('should set logger to the default logger by default', () => {
5354
const plugin = new ForkTsCheckerWebpackPlugin({});
5455

55-
expect(plugin['logger']).toBe(console);
56+
expect(plugin['logger']).toBe(defaultLogger);
5657
});
5758

5859
it('should set watch to empty array by default', () => {

0 commit comments

Comments
 (0)