UNPKG

next-openapi-gen

Version:

Automatically generate OpenAPI 3.0 documentation from Next.js projects, with support for Zod schemas and TypeScript types.

40 lines (39 loc) 1.21 kB
class Logger { config = null; init(config) { this.config = config; } getCallerInfo() { const stack = new Error().stack; if (!stack) return 'Unknown'; const lines = stack.split('\n'); // Skip: Error, getCallerInfo, log/warn/error const callerLine = lines[3] || lines[2]; // Extract class/function name const match = callerLine.match(/at (\w+)\.(\w+)|at (\w+)/); if (match) { return match[1] || match[3] || 'Unknown'; } return 'Unknown'; } log(message, ...args) { const source = this.getCallerInfo(); console.log(`[${source}] ${message}`, ...args); } warn(message, ...args) { const source = this.getCallerInfo(); console.warn(`[${source}] ${message}`, ...args); } error(message, ...args) { const source = this.getCallerInfo(); console.error(`[${source}] ${message}`, ...args); } debug(message, ...args) { if (this.config?.debug) { const source = this.getCallerInfo(); console.log(`[${source}] ${message}`, ...args); } } } export const logger = new Logger();