UNPKG

pocketbase-tools

Version:

A TypeScript toolkit for PocketBase, featuring a standard service/action/types layered structure. It provides interfaces and implementations for common business logic such as users, products, company profiles, and file utilities, making it suitable for se

33 lines (32 loc) 1.06 kB
// utils/logger.ts export class Logger { constructor(enableConsole) { // 默认: 非生产环境输出日志,生产环境不输出 this.enableConsole = typeof enableConsole === "boolean" ? enableConsole : process.env.NODE_ENV !== "production"; } success(message, data) { if (this.enableConsole) { console.log(`✅ 成功: ${message}`, data ? JSON.stringify(data) : ""); } } error(message, error) { if (this.enableConsole) { console.error(`❌ 错误: ${message}`, error ? JSON.stringify(error) : ""); } } warn(message, data) { if (this.enableConsole) { console.warn(`⚠️ 警告: ${message}`, data ? JSON.stringify(data) : ""); } } info(message, data) { if (this.enableConsole) { console.info(`ℹ️ 信息: ${message}`, data ? JSON.stringify(data) : ""); } } } // 默认导出: 根据 NODE_ENV 自动判断 export const logger = new Logger();