@azure/logger-js
Version:
Simple logger for JavaScript projects
165 lines • 5.75 kB
TypeScript
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
/**
* An interface for an object that writes logs.
*/
export interface Logger {
/**
* Log the provided text as informational.
* @param text The text to log.
*/
logInfo(text: string | string[]): Promise<unknown>;
/**
* Log the provided text as an error.
* @param text The text to log.
*/
logError(text: string | string[]): Promise<unknown>;
/**
* Log the provided text as a warning.
* @param text The text to log.
*/
logWarning(text: string | string[]): Promise<unknown>;
/**
* Log the provided text as a section header.
* @param text The text to log.
*/
logSection(text: string | string[]): Promise<unknown>;
/**
* Log the provided text as a verbose log.
* @param text The text to log.
*/
logVerbose(text: string | string[]): Promise<unknown>;
}
/**
* Add the provided prefix to each message logged through the resulting Logger.
* @param toWrap The Logger to wrap.
* @param prefix The prefix to add to each log message.
*/
export declare function prefix(toWrap: Logger, prefix: string | (() => string)): Logger;
/**
* Indent the messages logged by the resulting Logger.
* @param toWrap The Logger to wrap.
* @param indentation The indentation to add to the Logger's messages.
*/
export declare function indent(toWrap: Logger, indentation?: string | number): Logger;
/**
* Get a logger that will log to each of the provided loggers when it is logged to.
* @param loggers The loggers to log to.
*/
export declare function getCompositeLogger(...loggers: (Logger | undefined)[]): Logger;
/**
* The options that can be provided when creating a Logger.
*/
export interface LoggerOptions {
/**
* Log the provided text as informational.
* @param text The text to log.
*/
logInfo?: boolean | ((text: string | string[]) => unknown);
/**
* Log the provided text as an error.
* @param text The text to log.
*/
logError?: boolean | ((text: string | string[]) => unknown);
/**
* Log the provided text as a warning.
* @param text The text to log.
*/
logWarning?: boolean | ((text: string | string[]) => unknown);
/**
* Log the provided text as a section header.
* @param text The text to log.
*/
logSection?: boolean | ((text: string | string[]) => unknown);
/**
* Log the provided text as a verbose log.
* @param text The text to log.
*/
logVerbose?: boolean | ((text: string | string[]) => unknown);
/**
* Type of the logger.
*/
type?: "devops" | "console";
}
export declare function getLogFunction(optionsFunction: undefined | boolean | ((text: string | string[]) => unknown), normalFunction: (text: string | string[]) => unknown, undefinedUsesNormalFunction?: boolean): (text: string | string[]) => Promise<unknown>;
/**
* Wrap the provided Logger with the provided options.
* @param toWrap The Logger to wrap.
* @param options The options that should be applied to the wrapped Logger.
* @returns The newly created Logger that wraps the provided Logger using the provided options.
*/
export declare function wrapLogger(toWrap: Logger, options: LoggerOptions): Logger;
/**
* Get a Logger that will send its logs to the console.
*/
export declare function getConsoleLogger(options?: LoggerOptions): Logger;
/**
* A Logger that will store its logs in memory.
*/
export interface InMemoryLogger extends Logger {
/**
* All of the logs that have been written to this Logger.
*/
allLogs: string[];
/**
* The informational logs that have been written to this Logger.
*/
infoLogs: string[];
/**
* The error logs that have been written to this Logger.
*/
errorLogs: string[];
/**
* The warning logs that have been written to this Logger.
*/
warningLogs: string[];
/**
* The section header logs that have been written to this Logger.
*/
sectionLogs: string[];
/**
* The verbose logs that have been written to this Logger.
*/
verboseLogs: string[];
}
/**
* Get a Logger that will store its logs in memory.
*/
export declare function getInMemoryLogger(options?: LoggerOptions): InMemoryLogger;
export interface AzureDevOpsLoggerOptions extends LoggerOptions {
toWrap?: Logger;
}
/**
* Get a Logger that will output prefixes for certain types of logs in the Azure DevOps environment.
*/
export declare function getAzureDevOpsLogger(options?: AzureDevOpsLoggerOptions): Logger;
/**
* Get the default Logger based on the command line arguments.
* @returns The default Logger based on the command line arguments.
*/
export declare function getDefaultLogger(options?: LoggerOptions): Logger;
/**
* Prefix the provided logger's logs with a UTC timestamp
*/
export declare function timestamps(logger: Logger): Logger;
/**
* Prefix the provided logger's logs with line numbers.
*/
export declare function lineNumbers(logger: Logger, firstLineNumber?: number): Logger;
export declare function toArray(text: string | string[]): string[];
export declare function joinLines(text: string | string[]): string;
/**
* Get the lines of the provided text.
* @param text The text to get the lines of.
*/
export declare function getLines(text: string | undefined): string[];
/**
* Wrap the provided logger with logic that will split logs into individual lines before they are
* logged.
* @param logger The Logger to wrap.
*/
export declare function splitLines(logger: Logger): Logger;
//# sourceMappingURL=logger.d.ts.map