feat(logging): add log level env variable (#2299)
This commit is contained in:
1 parent
6420feee72
commit
67d48e11d7
31 files changed
+202
-183
No files matched your search
@@ -0,0 +1,24 @@
|
||||
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 };
|
||||
Reference in new issue
Block a user