Skip to content

Commit

Permalink
feat(@angular-devkit/core): createConsoleLogger now accepts 2 param…
Browse files Browse the repository at this point in the history
…eters to add custom `stdout` and `stderr`
  • Loading branch information
alan-agius4 authored and hansl committed Sep 18, 2018
1 parent 40129cc commit 04ed301
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/angular_devkit/core/node/cli-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@
import { filter } from 'rxjs/operators';
import { logging, terminal } from '../src';

export interface ProcessOutput {
write(buffer: string | Buffer): boolean;
}

/**
* A Logger that sends information to STDOUT and STDERR.
*/
export function createConsoleLogger(verbose = false): logging.Logger {
export function createConsoleLogger(
verbose = false,
stdout: ProcessOutput = process.stdout,
stderr: ProcessOutput = process.stderr,
): logging.Logger {
const logger = new logging.IndentLogger('cling');

logger
.pipe(filter(entry => (entry.level != 'debug' || verbose)))
.subscribe(entry => {
let color: (s: string) => string = x => terminal.dim(terminal.white(x));
let output = process.stdout;
let output = stdout;
switch (entry.level) {
case 'info':
color = terminal.white;
Expand All @@ -29,11 +36,11 @@ export function createConsoleLogger(verbose = false): logging.Logger {
break;
case 'error':
color = terminal.red;
output = process.stderr;
output = stderr;
break;
case 'fatal':
color = (x: string) => terminal.bold(terminal.red(x));
output = process.stderr;
output = stderr;
break;
}

Expand Down

0 comments on commit 04ed301

Please sign in to comment.