fix: deallocate syslog file transport at shutdown

This commit is contained in:
Ben Allfree 2024-02-10 16:19:55 +00:00
parent 2aaab9768b
commit cc11b976f4

View File

@ -4,18 +4,18 @@ import * as winston from 'winston'
import 'winston-syslog' import 'winston-syslog'
export function SyslogLogger(instanceId: string, target: string) { export function SyslogLogger(instanceId: string, target: string) {
// @ts-ignore
const syslogTransport = new winston.transports.Syslog({
host: `localhost`,
port: SYSLOGD_PORT(),
app_name: instanceId,
}) as winston.transport
const logger = winston.createLogger({ const logger = winston.createLogger({
format: winston.format.printf((info) => { format: winston.format.printf((info) => {
return info.message return info.message
}), }),
transports: [ transports: [syslogTransport],
// @ts-ignore
new winston.transports.Syslog({
host: `localhost`,
port: SYSLOGD_PORT(),
app_name: instanceId,
}),
],
}) })
const { error, warn } = LoggerService() const { error, warn } = LoggerService()
@ -31,6 +31,7 @@ export function SyslogLogger(instanceId: string, target: string) {
logger.error(msg) logger.error(msg)
}, },
shutdown: () => { shutdown: () => {
syslogTransport.close?.()
logger.close() logger.close()
}, },
} }