first commit

This commit is contained in:
baozaotumao2025
2026-07-18 21:10:39 +08:00
commit 1b90e552a5
91 changed files with 9056 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
import { sanitize } from './sanitize'
export type LogContext = Record<string, unknown>
type Level = 'debug' | 'info' | 'warn' | 'error'
const weights: Record<Level, number> = { debug: 10, info: 20, warn: 30, error: 40 }
const configuredLevel = (import.meta.env.VITE_LOG_LEVEL || 'info') as Level
function write(level: Level, message: string, context: LogContext = {}) {
if (weights[level] < (weights[configuredLevel] ?? weights.info)) return
const entry = sanitize({ timestamp: new Date().toISOString(), level, message, ...context })
console[level](entry)
}
export const logger = {
debug: (message: string, context?: LogContext) => write('debug', message, context),
info: (message: string, context?: LogContext) => write('info', message, context),
warn: (message: string, context?: LogContext) => write('warn', message, context),
error: (message: string, context?: LogContext) => write('error', message, context),
}