feat(logging): add log level env variable (#2299)

This commit is contained in:
Meier Lukas
2025-02-18 22:54:15 +01:00
committed by GitHub
parent 6420feee72
commit 67d48e11d7
31 changed files with 202 additions and 183 deletions

View File

@@ -0,0 +1,41 @@
import { Redis } from "ioredis";
import superjson from "superjson";
import Transport from "winston-transport";
//
// Inherit from `winston-transport` so you can take advantage
// of the base functionality and `.exceptions.handle()`.
//
export class RedisTransport extends Transport {
private redis: Redis | null = null;
/**
* Log the info to the Redis channel
*/
log(info: { message: string; timestamp: string; level: string }, callback: () => void) {
setImmediate(() => {
this.emit("logged", info);
});
if (!this.redis) {
// Is only initialized here because it did not work when initialized in the constructor or outside the class
this.redis = new Redis();
}
this.redis
.publish(
"pubSub:logging",
superjson.stringify({
message: info.message,
timestamp: info.timestamp,
level: info.level,
}),
)
.then(() => {
callback();
})
.catch(() => {
// Ignore errors
});
}
}