UNPKG

@rushstack/heft

Version:

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

70 lines 2.34 kB
"use strict"; // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. Object.defineProperty(exports, "__esModule", { value: true }); exports.ScopedLogger = void 0; const terminal_1 = require("@rushstack/terminal"); const LoggingManager_1 = require("./LoggingManager"); 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 terminal_1.PrefixProxyTerminalProvider({ terminalProvider: options.terminalProvider, prefix: `[${this.loggerName}] ` }); this.terminal = new terminal_1.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_1.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_1.LoggingManager.getErrorMessage(warning)}`); if (this._shouldPrintStacks && warning.stack) { this.terminal.writeWarningLine(warning.stack); } } /** * {@inheritdoc IScopedLogger.resetErrorsAndWarnings} */ resetErrorsAndWarnings() { this._errors = []; this._warnings = []; } } exports.ScopedLogger = ScopedLogger; //# sourceMappingURL=ScopedLogger.js.map