refactor(ngcc): expose logging level on the logger (#35861)

PR Close #35861
This commit is contained in:
Pete Bacon Darwin
2020-03-05 10:42:28 +00:00
committed by Matias Niemelä
parent 98a9daf4f4
commit bdaab4184d
7 changed files with 33 additions and 21 deletions

View File

@ -5,7 +5,7 @@
* 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';
import {LogLevel, Logger} from './logger';
const RESET = '\x1b[0m';
const RED = '\x1b[31m';
@ -16,13 +16,6 @@ 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.
*
@ -30,17 +23,17 @@ export enum LogLevel {
* constructor parameter.
*/
export class ConsoleLogger implements Logger {
constructor(private logLevel: LogLevel) {}
constructor(public level: LogLevel) {}
debug(...args: string[]) {
if (this.logLevel <= LogLevel.debug) console.debug(DEBUG, ...args);
if (this.level <= LogLevel.debug) console.debug(DEBUG, ...args);
}
info(...args: string[]) {
if (this.logLevel <= LogLevel.info) console.info(...args);
if (this.level <= LogLevel.info) console.info(...args);
}
warn(...args: string[]) {
if (this.logLevel <= LogLevel.warn) console.warn(WARN, ...args);
if (this.level <= LogLevel.warn) console.warn(WARN, ...args);
}
error(...args: string[]) {
if (this.logLevel <= LogLevel.error) console.error(ERROR, ...args);
if (this.level <= LogLevel.error) console.error(ERROR, ...args);
}
}

View File

@ -11,8 +11,16 @@
* output from the standard ConsoleLogger.
*/
export interface Logger {
level: LogLevel;
debug(...args: string[]): void;
info(...args: string[]): void;
warn(...args: string[]): void;
error(...args: string[]): void;
}
export enum LogLevel {
debug,
info,
warn,
error,
}