mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
This allows CLI usage to filter excessive log messages and integrations like webpack plugins to provide their own logger. // FW-1198 PR Close #29591
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
/**
|
|
* @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);
|
|
}
|
|
}
|