Skip to content

How to send the correct PID in forking service? #101

@airtower-luna

Description

@airtower-luna

When initializing Formatter3164 or Formatter5424 I have to provide a fixed PID, or let the defaults use the current PID (which is then also fixed from there). This creates a problem for services that fork after initializing logging (in my case to put the process into the background, would also apply to services that fork for parallel processing): Any log messages written after forking will log an incorrect PID.

The documentation example sets the PID to 0, and I've seen systemd-journald replace it with the actual PID of the sending process, but not all syslog implementations do that, or could be patched to (getting the PID from a unix socket client should work, from a TCP/UDP socket not so much).

The log crate documentation says that log::set_logger/log::set_boxed_logger may only be called once, so reinitializing it after forking is not an option. Initializing logging after forking would mean I can't send errors that occur before to syslog.

Am I missing some way to use the current PID at the time a log message is written, or update the formatter PID when forking? Or if not, could you add one?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions