@unito/integration-sdk
Version:
Integration SDK
82 lines (81 loc) • 3.2 kB
TypeScript
type PrimitiveValue = undefined | null | string | string[] | number | number[] | boolean | boolean[];
type Value = {
[key: string]: PrimitiveValue | Value | PrimitiveValue[] | Value[];
};
export type Metadata = Value & {
message?: never;
};
type ForbidenMetadataKey = 'message';
/**
* Logger class that can be configured with metadata add creation and when logging to add additional context to your logs.
*/
export default class Logger {
private isDisabled;
private metadata;
constructor(metadata?: Metadata, isDisabled?: boolean);
/**
* Logs a message with the 'log' log level.
* @param message The message to be logged.
* @param metadata Optional metadata to be associated with the log message.
*/
log(message: string, metadata?: Metadata): void;
/**
* Logs an error message with the 'error' log level.
* @param message The error message to be logged.
* @param metadata Optional metadata to be associated with the log message.
*/
error(message: string, metadata?: Metadata): void;
/**
* Logs a warning message with the 'warn' log level.
* @param message The warning message to be logged.
* @param metadata Optional metadata to be associated with the log message.
*/
warn(message: string, metadata?: Metadata): void;
/**
* Logs an informational message with the 'info' log level.
* @param message The informational message to be logged.
* @param metadata Optional metadata to be associated with the log message.
*/
info(message: string, metadata?: Metadata): void;
/**
* Logs a debug message with the 'debug' log level.
* @param message The debug message to be logged.
* @param metadata Optional metadata to be associated with the log message.
*/
debug(message: string, metadata?: Metadata): void;
/**
* Decorates the logger with additional metadata.
* @param metadata Additional metadata to be added to the logger.
*/
decorate(metadata: Metadata): void;
/**
* Return a copy of the Logger's metadata.
* @returns The {@link Metadata} associated with the logger.
*/
getMetadata(): Metadata;
/**
* Sets a key-value pair in the metadata. If the key already exists, it will be overwritten.
*
* @param key Key of the metadata to be set.
* May be any string other than 'message', which is reserved for the actual message logged.
* @param value Value of the metadata to be set.
*/
setMetadata<Key extends string>(key: Key extends ForbidenMetadataKey ? never : Key, value: PrimitiveValue | Value): void;
/**
* Clears the Logger's metadata.
*/
clearMetadata(): void;
private send;
private static snakifyKeys;
private static pruneSensitiveMetadata;
/**
* Colorizes the log message based on the log level and status codes.
* @param message The message to colorize.
* @param metadata The metadata associated with the log.
* @param logLevel The log level of the message.
* @returns The colorized output string.
*/
private static colorize;
}
export declare const NULL_LOGGER: Logger;
export {};