Closed bryanburgers closed 7 years ago
Hey Bryan!
Thanks for your thoughts and PR! I am delighted that other people are participating to this module :)
I actually discovered this problem before and finally named my node processes in the systemd unit files. But I know this is just a solution for daemons. And not a very good one as well.
I can confirm that your proposed solution works. But (Don't get me wrong!) I don't like the way how the identifier ist set. I think it is not a good habit to hold a state globally in the module. It may interfere if it is used by several other modules independently.
When I first discovered that process.title
is not the best solution to set the identifier, I thought about a breaking change to the API (resp. releasing version 2.0.0). This way every module using node-systemd-journald can hold their very own instance. See my example code:
const Jorunald = require( 'systemd-journald' );
// Create an instance of Journald for logging.
// The parameter holds an object containing default fields. They may be overwritten by logging calls.
// Of course it can have other default fields than just the syslog_identifier.
const log = new Journald( { syslog_identifier: 'foobar' } );
log.debug( ... );
What do you think?
Ha! I actually had a very similar example to that in my initial issue, but then removed it because I wasn't sure if you'd like a breaking version change. I like that direction.
Also, I am doing systemd daemons, and would be curious to see how you set it in your systemd file.
I don't have problems with breaking changes at all. I try do my very best to stick with semantic versioning. If everybody else would do that, we all do not have to concern about breaking changes. But before we do these changes, I'm going to warn the winston-systemd guys - they are requiring the lastest version of this module and ignore semantic versioning ;)
According to the systemd.exec docu just add SyslogIdentifier=foobar
to the [Service]
section.
Implementation in PR #8
I'm surprised the SyslogIdentifier
works when using this module. https://lists.freedesktop.org/archives/systemd-devel/2015-June/032816.html seems to suggest that SyslogIdentifier
only works when outputting to stdout or stderr, not when using sd_journal_(print|send)
.
I couldn't get it to work on systemd 229 (Ubuntu 16.04.1).
Sry, wasn't feeling well the last days. Merge will happen today.
Yes, you are right. I was wrong. Tested it and failed, too.
process.title
is limited, according to the node docs.It would be awesome if there was a way to specify the syslog identifier without mucking with
process.title
.One idea would be to allow
I did some very light testing on one machine, and I was able to set the syslog identifier with the following code:
which makes me think it might be as easy as checking if
log.identifier
is defined and, if it is, addingfields.SYSLOG_IDENTIFIER = log.identifier
, but I didn't test that.Thoughts?