strongloop / modern-syslog

modern-syslog
Other
49 stars 19 forks source link

Setting "ident" does not work #42

Open ceving opened 2 years ago

ceving commented 2 years ago

I have the following test program.

#! /usr/bin/node
'use strict';

const syslog = require('modern-syslog');

syslog.open ("myident",
             syslog.LOG_PID | syslog.LOG_ODELAY,
             syslog.LOG_LOCAL0);

syslog.log (syslog.LOG_INFO, "test myident " + Date.now());

syslog.close ();

When I run it, I get the following line in my Syslog:

Aug 24 12:06:51 kallisto node[9478]: test myident 1661335611978

I was expecting the string "myident" instead of "node".

When I do the same from the Bash,

logger -i -t myident test myident $(date +%s)

it works fine:

Aug 24 12:14:06 kallisto myident[9630]: test myident 1661336046
csimi commented 1 year ago

This happens because in modern-syslog log() is async (it's right there in the description but doesn't specify that the other methods are still sync). In your snippet close() runs earlier than log(). If you want to filter your logs into different directions you could use LOCAL0 to LOCAL7 instead of open/close spam:

syslog.open("myident", syslog.LOG_PID | syslog.LOG_ODELAY, 0);
syslog.log (syslog.LOG_INFO | syslog.LOG_LOCAL0, "test myfacility " + Date.now());
syslog.log (syslog.LOG_INFO | syslog.LOG_LOCAL1, "test myfacility " + Date.now());