modern-syslog icon indicating copy to clipboard operation
modern-syslog copied to clipboard

Setting "ident" does not work

Open ceving opened this issue 3 years ago • 1 comments

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

ceving avatar Aug 24 '22 10:08 ceving

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());

csimi avatar Sep 04 '23 11:09 csimi