-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syslog logs not flushed until app exits, and multiples are concatenated? #150
Comments
Ok, strange. I was looking at your source for any flush related code and decided to try switching to UDP. It works as expected now:
Is there a reason TCP is misbehaving? Am I mis-using the TCP protocol support? Or is this normal and my understanding of syslog has missed some more recent change? Thanks. |
having the same problem. |
We also have the same issue, seems there is even no api to flush the logs while using TCP. Can somebody from contributors check this? |
I'm having this problem or something similar. I run this code in an AWS lambda function, and my syslog events don't make it through when I use I'm using winston v3.7.2 and winston-syslog v2.5.0 const log = winston.createLogger({
levels: winston.config.syslog.levels,
transports: [
new winstonTransports.Console(),
new winstonTransports.Syslog({
level: 'debug',
host: process.env.LOG_HOST,
port: Number(process.env.LOG_PORT),
// protocol: 'tls4'
type: 'RFC5424',
localhost: 'lhost',
app_name: app,
facility: 'user',
format: winston.format.printf(logEvent =>
`${logEvent.message} ${JSON.stringify(logEvent)}`),
eol: '\n'
})
]
});
process.on('exit', () => {
console.debug('process exiting');
});
log.on('error', err => {
console.error('log error: %s', err);
});
log.on('finish', () => {
console.debug('done logging');
});
log.info('I have logged');
log.end(); |
I am also running into this issue on serverless functions. Is there any way to reliably wait for full flush? |
For anyone having similar issues to that of OP, double check if you have your new Syslog({
host,
port,
protocol,
app_name,
localhost,
level,
eol: '\n', // <- This line
}) Other than that, I've been having similar issues that of @NightWatchman . My serverless functions exit before logs finish sending. Switching to UDP makes them arrive but most times out of order. After trying several ways using const syslog = new Syslog({...}) as typeof Syslog & { queue: unknown[] }
const logger = new Winston.createLogger({..., transports: [syslog]})
async function flushSyslog(timeoutMs: number): Promise<boolean> => {
return new Promise<boolean>(resolve => {
let interval: NodeJS.Timeout
let timeout: NodeJS.Timeout
const finish = (result: boolean) => {
if (timeout) clearTimeout(timeout)
if (interval) clearInterval(interval)
resolve(result)
}
interval = setInterval(() => {
if (syslog.queue.length !== 0) return
finish(true)
}, 10)
timeout = setTimeout(() => {
finish(false)
}, timeoutMs)
})
} Just need to call this before finishing serverless functions and logs will arrive at destination. async function handler() {
try {
// code
} finally {
await flushSyslog(1000);
}
} |
Hi.
I'm finding that logs are not sent to my syslog server until after my app exits. I setup a straight Winston syslog config (with a Console transport added for good measure, which outputs the logs immediately), write a log and nothing appears in my syslog server until I Ctrl+C the app, then all 4 logs I wrote appear as a single syslog entry.
Here's the syslog message that gets written when exiting:
Is it that the logs aren't flushing? Why are all 4 bulk concatenated and not written as separate logs? Am I missing a log string terminator like newline (I don't see anything like this in the example usage)?
Thanks.
The text was updated successfully, but these errors were encountered: