Skip to content

Commit

Permalink
feat(@angular-devkit/core): support console logger color customization
Browse files Browse the repository at this point in the history
  • Loading branch information
clydin authored and alexeagle committed Feb 15, 2019
1 parent 889c254 commit d849834
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion etc/api/angular_devkit/core/node/_golden-api.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export declare function createConsoleLogger(verbose?: boolean, stdout?: ProcessOutput, stderr?: ProcessOutput): logging.Logger;
export declare function createConsoleLogger(verbose?: boolean, stdout?: ProcessOutput, stderr?: ProcessOutput, colors?: Partial<Record<logging.LogLevel, (s: string) => string>>): logging.Logger;

export declare function isDirectory(filePath: string): boolean;

Expand Down
10 changes: 5 additions & 5 deletions packages/angular_devkit/core/node/cli-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ export function createConsoleLogger(
verbose = false,
stdout: ProcessOutput = process.stdout,
stderr: ProcessOutput = process.stderr,
colors?: Partial<Record<logging.LogLevel, (s: string) => string>>,
): logging.Logger {
const logger = new logging.IndentLogger('cling');

logger
.pipe(filter(entry => (entry.level != 'debug' || verbose)))
.subscribe(entry => {
let color = terminal.dim;
let color = colors && colors[entry.level];
let output = stdout;
switch (entry.level) {
case 'info':
color = s => s;
break;
case 'warn':
color = (s: string) => terminal.bold(terminal.yellow(s));
color = color || (s => terminal.bold(terminal.yellow(s)));
output = stderr;
break;
case 'fatal':
case 'error':
color = (s: string) => terminal.bold(terminal.red(s));
color = color || (s => terminal.bold(terminal.red(s)));
output = stderr;
break;
}
Expand Down Expand Up @@ -66,7 +66,7 @@ export function createConsoleLogger(
while (message) {
const chunk = message.slice(0, chunkSize);
message = message.slice(chunkSize);
output.write(color(chunk));
output.write(color ? color(chunk) : chunk);
}
output.write('\n');
});
Expand Down

0 comments on commit d849834

Please sign in to comment.