Files
homarr/packages/log/src/index.ts
2025-02-18 22:54:15 +01:00

25 lines
778 B
TypeScript

import type { transport as Transport } from "winston";
import winston, { format, transports } from "winston";
import { env } from "./env";
import { RedisTransport } from "./redis-transport";
const logMessageFormat = format.printf(({ level, message, timestamp }) => {
return `${timestamp as string} ${level}: ${message as string}`;
});
const logTransports: Transport[] = [new transports.Console()];
// Only add the Redis transport if we are not in CI
if (!(Boolean(process.env.CI) || Boolean(process.env.DISABLE_REDIS_LOGS))) {
logTransports.push(new RedisTransport());
}
const logger = winston.createLogger({
format: format.combine(format.colorize(), format.timestamp(), logMessageFormat),
transports: logTransports,
level: env.LOG_LEVEL,
});
export { logger };