Despite rather scant and unclear documentation and an effective How-To for beginners, I have grown to like PSGI and am currently using it in one of my applications. What I would like to know is how do I manage logging across a multi-node application? What is considered "best practice" regarding logging in PSGI?
I recommend using Plack::Middleware::AccessLog for logging accessing and Plack::Middleware::LogDispatch for custom logging. They both in turn use the popular Log::Dispatch module.
The LogDispatch Middleware docs do not currently show you to how to use the logging object once it is set up. Here's an example:
my $app = sub {
my $env = shift;
$env->{'psgix.logger'}->({ level => "debug", message => "This is debug" });
return [ 200, [], [] ];
};
To address the multi-node concern, you could then use Log::Dispatch::Syslog which would send logging to rsyslog which could in turn to pass the log data on to another rsyslog server. In this way, all the nodes can log to a single central logging server.
With the flexibility of Log::Dispatch, you also have the option to log both locally and remotely for redundancy if you like. The logs sent to the central server could be considered primary, and the logging done locally could be considered backup in case the central log server is down for a bit.
Using a central log server has several advantages:
I currently using Log::Dispach and Rsyslog together in this way to manage a multi-node cluster myself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With