refactor(ngcc): expose logging level on the logger (#35861)
PR Close #35861
This commit is contained in:
parent
98a9daf4f4
commit
bdaab4184d
|
@ -8,8 +8,8 @@
|
|||
import {CachedFileSystem, NodeJSFileSystem, setFileSystem} from '../src/ngtsc/file_system';
|
||||
|
||||
import {AsyncNgccOptions, NgccOptions, SyncNgccOptions, mainNgcc} from './src/main';
|
||||
export {ConsoleLogger, LogLevel} from './src/logging/console_logger';
|
||||
export {Logger} from './src/logging/logger';
|
||||
export {ConsoleLogger} from './src/logging/console_logger';
|
||||
export {LogLevel, Logger} from './src/logging/logger';
|
||||
export {AsyncNgccOptions, NgccOptions, SyncNgccOptions} from './src/main';
|
||||
export {PathMappings} from './src/utils';
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ import * as yargs from 'yargs';
|
|||
|
||||
import {resolve, setFileSystem, CachedFileSystem, NodeJSFileSystem} from '../src/ngtsc/file_system';
|
||||
import {mainNgcc} from './src/main';
|
||||
import {ConsoleLogger, LogLevel} from './src/logging/console_logger';
|
||||
import {ConsoleLogger} from './src/logging/console_logger';
|
||||
import {LogLevel} from './src/logging/logger';
|
||||
|
||||
// CLI entry point
|
||||
if (require.main === module) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ import {LockFileAsync, LockFileSync} from './execution/lock_file';
|
|||
import {SingleProcessExecutorAsync, SingleProcessExecutorSync} from './execution/single_process_executor';
|
||||
import {ParallelTaskQueue} from './execution/task_selection/parallel_task_queue';
|
||||
import {SerialTaskQueue} from './execution/task_selection/serial_task_queue';
|
||||
import {ConsoleLogger, LogLevel} from './logging/console_logger';
|
||||
import {Logger} from './logging/logger';
|
||||
import {ConsoleLogger} from './logging/console_logger';
|
||||
import {LogLevel, Logger} from './logging/logger';
|
||||
import {hasBeenProcessed} from './packages/build_marker';
|
||||
import {NgccConfiguration} from './packages/configuration';
|
||||
import {EntryPoint, EntryPointJsonProperty, EntryPointPackageJson, SUPPORTED_FORMAT_PROPERTIES, getEntryPointFormat} from './packages/entry_point';
|
||||
|
|
|
@ -6,10 +6,12 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Logger} from '../../src/logging/logger';
|
||||
import {LogLevel, Logger} from '../../src/logging/logger';
|
||||
|
||||
export class MockLogger implements Logger {
|
||||
logs: {[P in keyof Logger]: string[][]} = {
|
||||
constructor(public level = LogLevel.info) {}
|
||||
|
||||
logs: {[P in Exclude<keyof Logger, 'level'>]: string[][]} = {
|
||||
debug: [],
|
||||
info: [],
|
||||
warn: [],
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* 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 {ConsoleLogger, DEBUG, ERROR, LogLevel, WARN} from '../../src/logging/console_logger';
|
||||
import {ConsoleLogger, DEBUG, ERROR, WARN} from '../../src/logging/console_logger';
|
||||
import {LogLevel} from '../../src/logging/logger';
|
||||
|
||||
describe('ConsoleLogger', () => {
|
||||
it('should pass through calls to Console', () => {
|
||||
|
@ -47,4 +48,11 @@ describe('ConsoleLogger', () => {
|
|||
logger.error('error', 'test');
|
||||
expect(console.error).toHaveBeenCalledWith(ERROR, 'error', 'test');
|
||||
});
|
||||
|
||||
it('should expose the logging level', () => {
|
||||
expect(new ConsoleLogger(LogLevel.debug).level).toEqual(LogLevel.debug);
|
||||
expect(new ConsoleLogger(LogLevel.info).level).toEqual(LogLevel.info);
|
||||
expect(new ConsoleLogger(LogLevel.warn).level).toEqual(LogLevel.warn);
|
||||
expect(new ConsoleLogger(LogLevel.error).level).toEqual(LogLevel.error);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue