* fix(deps): update dependency typescript-eslint to ^8.28.0 * fix: lint issues --------- Co-authored-by: homarr-renovate[bot] <158783068+homarr-renovate[bot]@users.noreply.github.com> Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
40 lines
996 B
TypeScript
40 lines
996 B
TypeScript
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);
|
|
});
|
|
|
|
// 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
|
|
});
|
|
}
|
|
}
|