@ogma/nestjs-module
Version:
A NestJS module for the Ogma logger
96 lines (95 loc) • 4.16 kB
TypeScript
import { LoggerService } from '@nestjs/common';
import { LogLevel, OgmaWritableLevel } from '@ogma/common';
import { Ogma } from '@ogma/logger';
import type { Styler } from '@ogma/styler';
import { OgmaServiceMeta } from './interfaces';
import { RequestContext } from './interfaces/request-context.interface';
export declare class OgmaService implements LoggerService {
private readonly requestContext?;
private readonly traceMethod;
private readonly context?;
private readonly ogma;
/**
* use Ogma to log at the FINE level
* @param message What to print to the Ogma instance
* @param context Optional context if you want to change what the original context was
*/
fine: (message: any, meta?: OgmaServiceMeta | string) => void;
/**
* use Ogma to log at the LOG level
* @param message What to print to the Ogma instance
* @param context Optional context if you want to change what the original context was
*/
log: (message: any, meta?: OgmaServiceMeta | string) => void;
constructor(ogma?: Ogma, context?: string, requestContext?: RequestContext, traceMethod?: Lowercase<OgmaWritableLevel>);
private getRequestId;
/**
* The [`@ogma/styler`](https://ogma.jaymcdoniel.dev/en/styler)
* instance that the logger uses for custom coloring without needing
* to manage a new styler instance
*/
get style(): Styler;
/**
* Change the log level during runtime
* @param the new log level to use
*/
setLogLevel(level: keyof typeof LogLevel): this;
/**
* use Ogma to log at the INFO level
* @param message What to print to the Ogma instance
* @param meta extra metadata for the log
*/
info(message: any, meta?: OgmaServiceMeta | string): void;
/**
* use Ogma to log at the ERROR level. You can provide a stack trace as well.
* @param message What to print to the Ogma instance
* @param meta additional information you can print about the log OR the stack trace to print
* @param context a string for the context in which the error log was called. This can be provided as a part of the meta, or as a third parameter to stay in line with Nest's LoggerService
*/
error(message: any, trace?: OgmaServiceMeta | string, context?: OgmaServiceMeta | string): void;
/**
* use Ogma to log at the WARN level
* @param message What to print to the Ogma instance
* @param meta extra metadata for the log
*/
warn(message: any, meta?: OgmaServiceMeta | string): void;
/**
* use Ogma to log at the DEBUG level
* @param message What to print to the Ogma instance
* @param meta extra metadata for the log
*/
debug(message: any, meta?: OgmaServiceMeta | string): void;
/**
* use Ogma to log at the FATAL level
* @param message What to print to the Ogma instance
* @param meta extra metadata for the log
*/
fatal(message: any, meta?: OgmaServiceMeta | string): void;
/**
* use Ogma to log at the SILLY level
* @param message What to print to the Ogma instance
* @param meta extra metadata for the log
*/
silly(message: any, meta?: OgmaServiceMeta | string): void;
/**
* use Ogma to log at the VERBOSE level
* @param message What to print to the Ogma instance
* @param meta extra metadata for the log
*/
verbose(message: any, meta?: OgmaServiceMeta | string): void;
/**
* A configurable method that will print at a different level depending on the configuration
* Normally this method will only be called via the `@Log()` decorator, but there's nothing
* stopping anyone else from using it too
* @param message the message to print
* @param meta extra metadata for the logs
*/
trace(message: any, meta?: OgmaServiceMeta): void;
/**
* A predefined method for printing errors to the Ogma instance
* @param error The error to print. Should be an Error or Exception object
* @param meta extra metadata for the log
*/
printError(error: Error, meta?: OgmaServiceMeta): void;
private printMessage;
}