@loglayer/transport
Version:
Base transport used to implement logging transports for loglayer.
130 lines (129 loc) • 4.07 kB
text/typescript
import { LogLayerTransport, LogLayerTransportParams, LogLevel, LogLevelPriority, LogLevelType, LogLevelType as LogLevelType$1 } from "@loglayer/shared";
//#region src/types.d.ts
/**
* Logging methods that are common to logging libraries
*/
interface LoggerLibrary {
info(...data: any[]): void;
warn(...data: any[]): void;
error(...data: any[]): void;
trace?: (...data: any[]) => void;
debug(...data: any[]): void;
fatal?: (...data: any[]) => void;
}
interface LoggerlessTransportConfig {
/**
* A user-defined identifier for the transport
*/
id?: string;
/**
* If false, the transport will not send logs to the logger.
* Default is true.
*/
enabled?: boolean;
/**
* If true, the transport will log to the console for debugging purposes
*/
consoleDebug?: boolean;
/**
* Minimum log level to process. Defaults to "trace".
*/
level?: LogLevelType$1;
}
interface LogLayerTransportConfig<LogLibrary> extends LoggerlessTransportConfig {
/**
* The logging library instance to use for logging
*/
logger: LogLibrary;
}
//#endregion
//#region src/BaseTransport.d.ts
/**
* For implementing libraries that are logging libraries that generally have an interface of:
* info(), warn(), error(), debug(), trace(), etc.
*
* @see {@link https://loglayer.dev/transports/creating-transports.html | Creating Transports}
*/
declare abstract class BaseTransport<LogLibrary> implements LogLayerTransport<LogLibrary> {
/**
* An identifier for the transport. If not defined, a random one will be generated.
*/
id?: string;
/**
* Instance of the logger library
*/
protected logger: LogLibrary;
/**
* If false, the transport will not send logs to the logger.
*/
enabled: boolean;
/**
* If true, the transport will log to the console for debugging purposes
*/
protected consoleDebug?: boolean;
/**
* Minimum log level to process. Defaults to "trace".
*/
level?: LogLevelType$1;
constructor(config: LogLayerTransportConfig<LogLibrary>);
/**
* LogLayer calls this to send logs to the transport
*/
_sendToLogger(params: LogLayerTransportParams): void;
/**
* Returns the logger instance attached to the transport
*/
getLoggerInstance(): LogLibrary;
/**
* Sends the log data to the logger for transport
*/
abstract shipToLogger(params: LogLayerTransportParams): any[];
}
//#endregion
//#region src/LoggerlessTransport.d.ts
/**
* For implementing libraries that aren't logging libraries
*
* @see {@link https://loglayer.dev/transports/creating-transports.html | Creating Transports}
*/
declare abstract class LoggerlessTransport implements LogLayerTransport {
/**
* An identifier for the transport. If not defined, a random one will be generated.
*/
id?: string;
/**
* If false, the transport will not send logs to the logger.
*/
enabled: boolean;
/**
* Minimum log level to process. Defaults to "trace".
*/
level?: LogLevelType$1;
/**
* If true, the transport will log to the console for debugging purposes
*/
protected consoleDebug?: boolean;
constructor(config: LoggerlessTransportConfig);
/**
* LogLayer calls this to send logs to the transport
*/
_sendToLogger(params: LogLayerTransportParams): void;
/**
* Returns the logger instance attached to the transport
*/
getLoggerInstance(): void;
/**
* Sends the log data to the logger for transport
*/
abstract shipToLogger(params: LogLayerTransportParams): any[];
}
//#endregion
//#region src/test-utils.d.ts
/**
* Shows what the logging library output looks like under a transport
* @param label A name for the test
* @param logLayerInstance The loglayer instance to use for logging
*/
declare function testTransportOutput(label: string, logLayerInstance: any): void;
//#endregion
export { BaseTransport, type LogLayerTransport, LogLayerTransportConfig, type LogLayerTransportParams, LogLevel, LogLevelPriority, type LogLevelType, LoggerLibrary, LoggerlessTransport, LoggerlessTransportConfig, testTransportOutput };