UNPKG

@rushstack/heft

Version:

Build all your JavaScript projects the same way: A way that works.

66 lines 2.17 kB
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. import { PrefixProxyTerminalProvider, Terminal } from '@rushstack/terminal'; import { LoggingManager } from './LoggingManager'; export class ScopedLogger { get _shouldPrintStacks() { // TODO: Consider dumping stacks and more verbose logging to a file return this._options.getShouldPrintStacks(); } get errors() { return [...this._errors]; } get warnings() { return [...this._warnings]; } /** * @internal */ constructor(options) { this._errors = []; this._warnings = []; this._options = options; this.loggerName = options.loggerName; this.terminalProvider = new PrefixProxyTerminalProvider({ terminalProvider: options.terminalProvider, prefix: `[${this.loggerName}] ` }); this.terminal = new Terminal(this.terminalProvider); } /** * {@inheritdoc IScopedLogger.hasErrors} */ get hasErrors() { return this._errors.length > 0; } /** * {@inheritdoc IScopedLogger.emitError} */ emitError(error) { this._options.errorHasBeenEmittedCallback(); this._errors.push(error); this.terminal.writeErrorLine(`Error: ${LoggingManager.getErrorMessage(error)}`); if (this._shouldPrintStacks && error.stack) { this.terminal.writeErrorLine(error.stack); } } /** * {@inheritdoc IScopedLogger.emitWarning} */ emitWarning(warning) { this._options.warningHasBeenEmittedCallback(); this._warnings.push(warning); this.terminal.writeWarningLine(`Warning: ${LoggingManager.getErrorMessage(warning)}`); if (this._shouldPrintStacks && warning.stack) { this.terminal.writeWarningLine(warning.stack); } } /** * {@inheritdoc IScopedLogger.resetErrorsAndWarnings} */ resetErrorsAndWarnings() { this._errors = []; this._warnings = []; } } //# sourceMappingURL=ScopedLogger.js.map