feat: umami migration
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
|
||||
|
||||
export interface LoggerService {
|
||||
debug(message: string, context?: Record<string, unknown>): void;
|
||||
info(message: string, context?: Record<string, unknown>): void;
|
||||
warn(message: string, context?: Record<string, unknown>): void;
|
||||
error(message: string, context?: Record<string, unknown>): void;
|
||||
child(context: Record<string, unknown>): LoggerService;
|
||||
trace(msg: string, ...args: any[]): void;
|
||||
debug(msg: string, ...args: any[]): void;
|
||||
info(msg: string, ...args: any[]): void;
|
||||
warn(msg: string, ...args: any[]): void;
|
||||
error(msg: string, ...args: any[]): void;
|
||||
fatal(msg: string, ...args: any[]): void;
|
||||
child(bindings: Record<string, any>): LoggerService;
|
||||
}
|
||||
|
||||
13
lib/services/logging/noop-logger-service.ts
Normal file
13
lib/services/logging/noop-logger-service.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { LoggerService } from "./logger-service";
|
||||
|
||||
export class NoopLoggerService implements LoggerService {
|
||||
trace() {}
|
||||
debug() {}
|
||||
info() {}
|
||||
warn() {}
|
||||
error() {}
|
||||
fatal() {}
|
||||
child() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
import { pino, type Logger as PinoLogger } from "pino";
|
||||
import pino, { Logger as PinoLogger } from "pino";
|
||||
import type { LoggerService } from "./logger-service";
|
||||
import { config } from "../../config";
|
||||
|
||||
export class PinoLoggerService implements LoggerService {
|
||||
private logger: PinoLogger;
|
||||
private readonly logger: PinoLogger;
|
||||
|
||||
constructor(name?: string, parent?: PinoLogger) {
|
||||
if (parent) {
|
||||
this.logger = parent.child({ name });
|
||||
} else {
|
||||
// In Next.js, especially in the Edge runtime or during instrumentation,
|
||||
// pino transports (which use worker threads) can cause issues.
|
||||
// We disable transport in production and during instrumentation.
|
||||
const useTransport =
|
||||
config.isDevelopment && typeof window === "undefined";
|
||||
|
||||
@@ -27,29 +30,40 @@ export class PinoLoggerService implements LoggerService {
|
||||
}
|
||||
}
|
||||
|
||||
debug(message: string, context?: Record<string, unknown>) {
|
||||
if (context) this.logger.debug(context, message);
|
||||
else this.logger.debug(message);
|
||||
trace(msg: string, ...args: any[]) {
|
||||
// @ts-expect-error - pino types can be strict
|
||||
this.logger.trace(msg, ...args);
|
||||
}
|
||||
|
||||
info(message: string, context?: Record<string, unknown>) {
|
||||
if (context) this.logger.info(context, message);
|
||||
else this.logger.info(message);
|
||||
debug(msg: string, ...args: any[]) {
|
||||
// @ts-expect-error - pino types can be strict
|
||||
this.logger.debug(msg, ...args);
|
||||
}
|
||||
|
||||
warn(message: string, context?: Record<string, unknown>) {
|
||||
if (context) this.logger.warn(context, message);
|
||||
else this.logger.warn(message);
|
||||
info(msg: string, ...args: any[]) {
|
||||
// @ts-expect-error - pino types can be strict
|
||||
this.logger.info(msg, ...args);
|
||||
}
|
||||
|
||||
error(message: string, context?: Record<string, unknown>) {
|
||||
if (context) this.logger.error(context, message);
|
||||
else this.logger.error(message);
|
||||
warn(msg: string, ...args: any[]) {
|
||||
// @ts-expect-error - pino types can be strict
|
||||
this.logger.warn(msg, ...args);
|
||||
}
|
||||
|
||||
child(context: Record<string, unknown>): LoggerService {
|
||||
const childPino = this.logger.child(context);
|
||||
error(msg: string, ...args: any[]) {
|
||||
// @ts-expect-error - pino types can be strict
|
||||
this.logger.error(msg, ...args);
|
||||
}
|
||||
|
||||
fatal(msg: string, ...args: any[]) {
|
||||
// @ts-expect-error - pino types can be strict
|
||||
this.logger.fatal(msg, ...args);
|
||||
}
|
||||
|
||||
child(bindings: Record<string, any>): LoggerService {
|
||||
const childPino = this.logger.child(bindings);
|
||||
const service = new PinoLoggerService();
|
||||
// @ts-expect-error - accessing private member for child creation
|
||||
service.logger = childPino;
|
||||
return service;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user