feat(compiler-cli): ngcc - make logging more configurable (#29591)
This allows CLI usage to filter excessive log messages and integrations like webpack plugins to provide their own logger. // FW-1198 PR Close #29591
This commit is contained in:

committed by
Jason Aden

parent
39345b6fae
commit
8d3d75e454
46
packages/compiler-cli/ngcc/src/logging/console_logger.ts
Normal file
46
packages/compiler-cli/ngcc/src/logging/console_logger.ts
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {Logger} from './logger';
|
||||
|
||||
const RESET = '\x1b[0m';
|
||||
const RED = '\x1b[31m';
|
||||
const YELLOW = '\x1b[33m';
|
||||
const BLUE = '\x1b[36m';
|
||||
|
||||
export const DEBUG = `${BLUE}Debug:${RESET}`;
|
||||
export const WARN = `${YELLOW}Warning:${RESET}`;
|
||||
export const ERROR = `${RED}Error:${RESET}`;
|
||||
|
||||
export enum LogLevel {
|
||||
debug,
|
||||
info,
|
||||
warn,
|
||||
error,
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple logger that outputs directly to the Console.
|
||||
*
|
||||
* The log messages can be filtered based on severity via the `logLevel`
|
||||
* constructor parameter.
|
||||
*/
|
||||
export class ConsoleLogger implements Logger {
|
||||
constructor(private logLevel: LogLevel) {}
|
||||
debug(...args: string[]) {
|
||||
if (this.logLevel <= LogLevel.debug) console.debug(DEBUG, ...args);
|
||||
}
|
||||
info(...args: string[]) {
|
||||
if (this.logLevel <= LogLevel.info) console.info(...args);
|
||||
}
|
||||
warn(...args: string[]) {
|
||||
if (this.logLevel <= LogLevel.warn) console.warn(WARN, ...args);
|
||||
}
|
||||
error(...args: string[]) {
|
||||
if (this.logLevel <= LogLevel.error) console.error(ERROR, ...args);
|
||||
}
|
||||
}
|
18
packages/compiler-cli/ngcc/src/logging/logger.ts
Normal file
18
packages/compiler-cli/ngcc/src/logging/logger.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implement this interface if you want to provide different logging
|
||||
* output from the standard ConsoleLogger.
|
||||
*/
|
||||
export interface Logger {
|
||||
debug(...args: string[]): void;
|
||||
info(...args: string[]): void;
|
||||
warn(...args: string[]): void;
|
||||
error(...args: string[]): void;
|
||||
}
|
Reference in New Issue
Block a user