UNPKG

@mikro-orm/core

Version:

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.

64 lines (63 loc) 2.57 kB
import type { AnyString, Dictionary, Highlighter } from '../typings.js'; /** Interface for ORM logging, supporting namespaced log levels and query logging. */ export interface Logger { /** * Logs a message inside given namespace. */ log(namespace: LoggerNamespace | AnyString, message: string, context?: LogContext): void; /** * Logs error message inside given namespace. */ error(namespace: LoggerNamespace | AnyString, message: string, context?: LogContext): void; /** * Logs warning message inside given namespace. */ warn(namespace: LoggerNamespace | AnyString, message: string, context?: LogContext): void; /** * Logs a message inside given namespace. */ logQuery(context: LogContext): void; /** * Sets active namespaces. Pass `true` to enable all logging. */ setDebugMode(debugMode: boolean | LoggerNamespace[]): void; /** Checks whether logging is enabled for the given namespace. */ isEnabled(namespace: LoggerNamespace, context?: LogContext): boolean; } /** Available logging namespaces that can be individually enabled or disabled. */ export type LoggerNamespace = 'query' | 'query-params' | 'schema' | 'discovery' | 'info' | 'deprecated' | 'slow-query'; /** Contextual metadata passed alongside log messages, including query details and timing. */ export interface LogContext extends Dictionary { query?: string; label?: string; namespace?: LoggerNamespace; params?: readonly unknown[]; took?: number; results?: number; affected?: number; level?: 'info' | 'warning' | 'error'; enabled?: boolean; debugMode?: LoggerNamespace[]; connection?: { type?: string; name?: string; }; } /** Options for constructing a Logger instance. */ export interface LoggerOptions { writer: (message: string) => void; debugMode?: boolean | LoggerNamespace[]; ignoreDeprecations?: boolean | string[]; highlighter?: Highlighter; usesReplicas?: boolean; } /** * Logger options to modify format output and overrides, including a label and additional properties that can be accessed by custom loggers. * * Differs from {@apilink LoggerOptions} in terms of how they are used; this type is primarily a public type meant to be used within methods like `em.find()`. * * @example * await em.findOne(User, 1, { logger: { label: 'user middleware' } }; * // [query] (user middleware) select * from user where id = 1; */ export type LoggingOptions = Pick<LogContext, 'label' | 'enabled' | 'debugMode'>;