import type bowser from 'bowser'; import { LogLevels } from './logLevel.js'; /** * Environments */ export declare enum Environment { PROD = "prod", STAGE = "stage", QA = "qa", DEV = "dev", PEG = "peg" } /** * base log schema fields */ export type BaseLogSchema = { /** * application log index. required */ index: string; /** * name of the current host or container */ host: string; /** * name of the current environment */ environment: Environment; /** * name of the current application. required */ appName: string; /** * version of the current application */ appVersion: string; /** * team that owns the application. required */ team: string; /** * aws region or datacenter identifier where the application is running */ location: string; /** * unique identifier for the logger instance */ correlationId: string; /** * application instance identifier. e.g: Encompass Instance ID */ instanceId: string; /** * tenant identifier. e.g: Encompass Customer ID */ customerId: string; /** * user identifier. e.g: Encompass User ID */ userId: string; /** * loan Id (optional prop). e.g: Loan Guid */ loanId?: string; /** * user agent details */ context: ReturnType; }; /** * Logger options */ export type LoggerOptions = { /** * application log index. required */ index: string; /** * name of the current host or container */ host?: string; /** * name of the current environment */ environment?: Environment; /** * name of the current application. required */ appName: string; /** * version of the current application */ appVersion?: string; /** * team that owns the application. required */ team: string; /** * aws region or datacenter identifier where the application is running */ location?: string; /** * application instance identifier. e.g: Encompass Instance ID */ instanceId?: string; /** * tenant identifier. e.g: Encompass Customer ID */ customerId?: string; /** * user identifier. e.g: Encompass User ID */ userId?: string; /** * loan Id. e.g: Loan Guid */ loanId?: string; /** * object that receives and processes the logs. default: Console. see {@link http}, {@link Console} */ transport?: Transport; /** * log message to console in addition to sending them to transport layer. default: false */ logEverythingToConsole?: boolean; }; /** * logger options that can be changed at runtime */ export type RuntimeLoggerOptions = Pick; /** * log message transport layer */ export type Transport = { /** * process log message * @param msg {@link LogMessage} */ log: (msg: LogMessage, logLevel?: LogLevels) => Promise; }; /** * HTTP transport configuration options for controlling log volume and API load. * All options are optional and have sensible defaults for backward compatibility. */ export type HttpTransportOptions = { /** * Milliseconds between batch flushes for non-critical logs. * @default 10000 */ flushInterval?: number; /** * Flush the batch early when it reaches this size, preventing unbounded memory growth. * @default 50 */ maxBatchSize?: number; /** * Max non-critical logs accepted per flush interval window. 0 = unlimited. * WARN, ERROR, and FATAL logs are never dropped by rate limiting. * @default 0 */ maxLogsPerInterval?: number; /** * Sampling rate for non-critical logs (DEBUG, INFO, AUDIT), between 0 and 1. * 1 = send all, 0.1 = send ~10%. WARN, ERROR, and FATAL logs are never sampled. * @default 1 */ samplingRate?: number; }; /** * message key value pairs */ type LogData = Record; /** * message base object */ export type BaseRecordObject = { /** * message string */ message: string; /** * error object if any */ exception?: Error; }; /** * message object */ export type LogRecord = BaseRecordObject & LogData; /** * log data with log level * @param logLevel {@link LogLevels} * @param message data to log. can be a string or {@link LogRecord} */ export type LogFunctionWithLogLevel = (logLevel: LogLevels, message: LogRecord | string) => void; /** * log data * @param message data to log. can be a string or {@link LogRecord} */ export type LogFunction = (message: LogRecord | string) => void; /** * Logger */ export type Logger = { /** * set log level. default: {@link LogLevels.INFO} */ setLogLevel: (level: LogLevels) => void; /** * get current log level * @returns current log level. {@link LogLevels} */ getLogLevel: () => LogLevels; /** * Change logger properties post initialization * @param options {@link RuntimeLoggerOptions} */ setOptions: (options: RuntimeLoggerOptions) => void; /** * log debug message */ debug: LogFunction; /** * log info message */ info: LogFunction; /** * log warning message */ warn: LogFunction; /** * log error message */ error: LogFunction; /** * log fatal message */ fatal: LogFunction; /** * log audit message */ audit: LogFunction; }; /** * log message object received by transport layer */ export type LogMessage = BaseLogSchema & { /** * time at which the log message was processed */ '@timestamp': string; /** * log level of the message. {@link LogLevels} */ level: keyof typeof LogLevels; /** * log message */ message: string; /** * The type of resource that the current request/message is working on: loan, contact, agent, etc. */ resourceType?: string; /** * The ID of the resource that the current request/message is working on. Only applicable when resourceType is also present */ resourceId?: string; } & LogData; export {};