UNPKG

simple-log-methods

Version:

a simple and opinionated logging library. plays well with aws lambda + cloudwatch.

53 lines (52 loc) 2 kB
import { type UniDuration } from '@ehmpathy/uni-time'; import type { LogLevel } from '../domain/constants'; import type { ContextLogTrail } from '../domain/LogTrail'; /** * enables input output logging and tracing for a method * * todo: - add tracing identifier w/ async-context * todo: - hookup visual tracing w/ external lib (vi...lo...) * todo: - bundle this with its own logging library which supports scoped logs */ export declare const withLogTrail: <TInput, TContext extends ContextLogTrail, TOutput>(logic: (input: TInput, context: TContext) => TOutput, { name: declaredName, log: logOptions, duration, }: { /** * specifies the name of the function, if the function does not have a name assigned already */ name?: string | undefined; /** * enable redacting parts of the input or output from logging */ log?: { /** * specifies the level to log the trail with * * note: * - defaults input & output logs to level .debug // todo: debug to .trail * - defaults error logs to level .warn * - error level is only overridable via the object form (to prevent accidental downgrade of error logs) */ level?: LogLevel | { input?: LogLevel | undefined; output?: LogLevel | undefined; error?: LogLevel | undefined; } | undefined; /** * what of the input to log */ input?: ((input: TInput, context: TContext) => any) | undefined; /** * what of the output to log */ output?: ((value: Awaited<TOutput>) => any) | undefined; /** * what of the error to log */ error?: ((error: Error) => any) | undefined; } | undefined; /** * specifies the threshold after which a duration will be included on the output log */ duration?: { threshold: UniDuration; } | undefined; }) => (input: TInput, context: TContext) => TOutput;