Skip to content

armgit / crm

Public Imported from GitHub
0

Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM.

TypeScript
677 B
Raw Blame
import { Injectable, Logger } from "@nestjs/common";
import type {
	MiddlewareOptions,
	MiddlewareResponse,
	TRPCMiddleware,
} from "nestjs-trpc";

@Injectable()
export class LoggingMiddleware implements TRPCMiddleware {
	private readonly logger = new Logger("tRPC");

	async use(opts: MiddlewareOptions): Promise<MiddlewareResponse> {
		const startedAt = Date.now();
		const result = await opts.next();
		const durationMs = Date.now() - startedAt;

		this.logger.log({
			message: `${opts.type} ${opts.path} ${result.ok ? "ok" : "err"} ${durationMs}ms`,
			type: opts.type,
			path: opts.path,
			outcome: result.ok ? "ok" : "err",
			durationMs,
		});

		return result;
	}
}