I've searched long and read much on daemons and logging, including Proc::Daemon and Log::Log4perl on using Log::Log4perl and Proc::Daemon. Although that example suggests initializing Log4perl after calling Init() works, I haven't been able to get that to work, and I need to do logging both before and after going into the background.
Basically, I need to start up a daemon process, have it process configuration and command line arguments and log to a file via log4perl. If anything fails during initialization, it will exit with a non-zero code, letting the caller know that the startup didn't succeed. After initialization, the process will daemonize and continue logging, hopefully to the same log file.
The problem I have is that I need to process config and log before I daemonize, or I can't return a meaningful exit status to the caller. I need to continue to log after I deamonize, and would like to log to the same FileRotate appender/file.
I've tried quite a few combinations, and cannot get log4perl to initialize at all after Proc::Daemon::Init, regardless of whether I have attempted to initialize a log before the Init() call.
If I initialize before the Init() call, I get all the config logging I would expect, but then nothing (naturally, since Init() closed all the FDs). I have tried reinitializing after Init, but as I stated above above, no matter what I do, I can't get any logging after Init().
There must be a proven recipe out there for exactly this situation:
I've looked at App::Daemon, which looks promising. But the description of how log4perl is initialize and handled is vague. What I don't understand is how to get access to the logger initialized by App::Daemon, and if the logger is available both before and after the call to daemonize().
Please, bless me Brothers, with the wisdom you hold within you.
In reply to Daemon w/ logging before and after background by batkins61
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |