Files
bedolaga-cabinet/src/utils/logger.ts
2026-01-18 05:26:47 +03:00

58 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Утилита для логирования только в development режиме
* В production логи не выводятся
*/
const isDev = import.meta.env.DEV
export const logger = {
log: (...args: unknown[]): void => {
if (isDev) {
console.log(...args)
}
},
warn: (...args: unknown[]): void => {
if (isDev) {
console.warn(...args)
}
},
error: (...args: unknown[]): void => {
// Ошибки логируем всегда (важно для отладки в production)
console.error(...args)
},
debug: (...args: unknown[]): void => {
if (isDev) {
console.debug(...args)
}
},
/**
* Создаёт логгер с префиксом для конкретного модуля
*/
createLogger: (prefix: string) => ({
log: (...args: unknown[]): void => {
if (isDev) {
console.log(`[${prefix}]`, ...args)
}
},
warn: (...args: unknown[]): void => {
if (isDev) {
console.warn(`[${prefix}]`, ...args)
}
},
error: (...args: unknown[]): void => {
console.error(`[${prefix}]`, ...args)
},
debug: (...args: unknown[]): void => {
if (isDev) {
console.debug(`[${prefix}]`, ...args)
}
},
}),
}
export default logger