Skip to content
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

Setting "ident" does not work #42

Open
ceving opened this issue Aug 24, 2022 · 1 comment
Open

Setting "ident" does not work #42

ceving opened this issue Aug 24, 2022 · 1 comment

Comments

@ceving
Copy link

ceving commented Aug 24, 2022

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
Copy link

csimi commented Sep 4, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants