feat(shared): types API, logger structuré, validation env.ts

This commit is contained in:
Hermann_Kitio 2026-04-17 17:24:21 +03:00
parent dbc9360b36
commit 476dfeeb08
3 changed files with 63 additions and 0 deletions

18
src/shared/lib/logger.ts Normal file
View file

@ -0,0 +1,18 @@
type LogLevel = 'debug' | 'info' | 'warn' | 'error'
type LogContext = Record<string, unknown>
function log(level: LogLevel, message: string, context?: LogContext): void {
if (import.meta.env.DEV) {
console[level](`[${level.toUpperCase()}] ${message}`, context ?? '')
return
}
const entry = { level, message, timestamp: new Date().toISOString(), ...context }
console[level](JSON.stringify(entry))
}
export const logger = {
debug: (msg: string, ctx?: LogContext) => log('debug', msg, ctx),
info: (msg: string, ctx?: LogContext) => log('info', msg, ctx),
warn: (msg: string, ctx?: LogContext) => log('warn', msg, ctx),
error: (msg: string, ctx?: LogContext) => log('error', msg, ctx),
}