feat(shared): types API, logger structuré, validation env.ts
This commit is contained in:
parent
dbc9360b36
commit
476dfeeb08
3 changed files with 63 additions and 0 deletions
18
src/shared/lib/logger.ts
Normal file
18
src/shared/lib/logger.ts
Normal 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),
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue