feat: umami migration

This commit is contained in:
2026-02-07 01:11:28 +01:00
parent 29d474a102
commit 9f6168592c
27 changed files with 3310 additions and 193 deletions

View File

@@ -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;
}

View 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;
}
}

View File

@@ -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;
}