@dynatrace/opentelemetry-core
Version:
Dynatrace OpenTelemetry core package
104 lines • 3.03 kB
TypeScript
import type { DiagLogger } from "@opentelemetry/api";
import { LoggingDestination, LoggingFlags } from "./Types";
export declare enum LogKind {
Info = "info ",
Warn = "warning",
Error = "error ",
Debug = "debug "
}
export declare class DtLogger {
/**
* Returns true if logger is enabled.
* Optionally the logging flag is checked
* @param flag Logging flag to check
* @returns true if log message will be sent out
*/
enabled(flag?: string): boolean;
/**
* Configure the logger.
* @param destination The logging destination to use
* @param flags The logging flags
*/
configure(destination?: LoggingDestination, flags?: LoggingFlags): void;
/**
* Formats and sends a log message.
* @param kind The kind of message (e.g. error/warning)
* @param component The component logging the message
* @param msg The actual message
*/
log(kind: LogKind, component: string, msg: string): void;
/**
* Helper to log an info message.
* @see log
*/
info: (component: string, msg: string) => void;
/**
* Helper to log a warning message.
* @see log
*/
warn: (component: string, msg: string) => void;
/**
* Helper to log an error message.
* @see log
*/
error: (component: string, msg: string) => void;
/**
* Helper to log a debug message.
* @see log
*/
debug: (component: string, msg: string) => void;
/**
* Helper to log an agent exception as warning.
* @param component The component logging the message
* @param e the exception to log
*/
logAgentException(component: string, e: unknown): void;
private _flags;
private _logFn?;
}
/**
* elementary logging interface
*/
export interface Logger {
/**
* true, if logging is enabled
*/
readonly enabled: boolean;
/**
* true, if debug logging is enabled
*/
readonly debugEnabled: boolean;
debug(msg: string): void;
info(msg: string): void;
warn(msg: string): void;
error(msg: string): void;
/**
* unified reporting of exceptions caught in agent code
* @param e
*/
logAgentException(e: unknown): void;
}
/**
* convenience class for component level logging
*/
export declare class ComponentLogger implements Logger, DiagLogger {
readonly componentName: string;
constructor(componentName: string, debugFlagName?: string);
readonly debugFlagName: string;
get enabled(): boolean;
get debugEnabled(): boolean;
info(msg: string): void;
warn(msg: string): void;
error(msg: string): void;
verbose(msg: string): void;
/**
* Helper to log a debug message.
* Note: check if debug logging is enabled before calling this API to avoid expensive
* log message composition
* @see log
*/
debug(msg: string): void;
logAgentException(e: unknown): void;
}
export declare const logger: DtLogger;
//# sourceMappingURL=Logger.d.ts.map