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

Added options to pass 'Log::Log4perl' as logger to Net::Server #121

Closed
wants to merge 1 commit into from

Conversation

Elhodred
Copy link

As Net::Server is able to use Log::Log4perl as logger, we can leverage it and use some of the advanced options that Log4perl provides.
For instance, a USR1 signal can be used to recreate the logs (hello logrotate). Here an example:

use strict;
use warnings;
use Plack::Handler::Starman;
use Plack::Builder;

$SIG{'USR1'} = 'IGNORE';

sub start {
        my $app = sub {
                die 'Hello World crashed!!!';
        };
        builder {
                mount '/' => builder { $app; };
        }
}

my $log_config = {
        "log4perl.rootLogger" => "INFO,LOGFILE",
        "log4perl.appender.LOGFILE" => "Log::Log4perl::Appender::File",
        "log4perl.appender.LOGFILE.filename" => "/var/log/test.log",
        "log4perl.appender.LOGFILE.layout"   => "Log::Log4perl::Layout::PatternLayout",
        "log4perl.appender.LOGFILE.layout.ConversionPattern" => "[%r] %F %L %m%n",
        "log4perl.appender.LOGFILE.recreate" => 1,
        "log4perl.appender.Logfile.recreate_check_signal" => "USR1"
};

my $server = Plack::Handler::Starman->new(listen => ["127.0.0.1:8080"], daemonize => 1, error_log => 'Log::Log4perl', log4perl_conf => $log_config);
$server->run(start());

With that example, you can remove /var/log/test.log, send a USR1 signal to the master process and the file will be recreated.

@davidcsi
Copy link

Nice! Very interesting!

@miyagawa
Copy link
Owner

You don't need this patch, Starman has an option to pass Net::Server options in net_server_args.

@miyagawa miyagawa closed this Apr 21, 2016
@Elhodred
Copy link
Author

Sometimes I think I'm blind. You are right, I didn't realise about net_server_args.
Thanks.

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

Successfully merging this pull request may close these issues.

None yet

3 participants