@stacksjs/logging
Version:
The Stacks logging system.
47 lines (46 loc) • 1.77 kB
TypeScript
/**
* Run a function with an attached log context (e.g., request ID).
* Use in HTTP middleware to propagate context through the request lifecycle.
*/
export declare function withLogContext<T>(context: LogContext, fn: () => T): T;
/**
* Get the current log context (if any).
*/
export declare function getLogContext(): LogContext | undefined;
declare function getLogger(): Promise<Logger>;
// Export convenience functions
export declare function dump(...args: any[]): Promise<void>;
export declare function dd(...args: any[]): Promise<never>;
export declare function echo(...args: any[]): Promise<void>;
export declare const log: Log;
export declare const struct: unknown;
// Request context propagation for structured logging
declare interface LogContext {
requestId?: string
userId?: string | number
[key: string]: unknown
}
export declare interface Log {
info: (...args: any[]) => Promise<void>
success: (msg: string) => Promise<void>
error: (err: string | Error | object | unknown, options?: LogErrorOptions) => Promise<void>
warn: (arg: string, options?: Record<string, any>) => Promise<void>
warning: (arg: string) => Promise<void>
debug: (...args: any[]) => Promise<void>
dump: (...args: any[]) => Promise<void>
dd: (...args: any[]) => Promise<void>
echo: (...args: any[]) => Promise<void>
time: (label: string) => (metadata?: Record<string, any>) => Promise<void>
syncWarn: (msg: string) => void
syncError: (msg: string) => void
fatal: (msg: string, exitCode?: number) => never
flush: () => Promise<void>
}
export type ErrorMessage = string;
export type LogErrorOptions = {
shouldExit: boolean
silent?: boolean
message?: ErrorMessage
} | any | Error;
// Export logger getter for debugging
export { getLogger as logger };