« blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Plugin/HTTP/Session.pm
↑ Summary
blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Plugin/Sentry.pm »
| 1 | package Dwarf::Plugin::Log::Dispatch::FileRotate; | ||
| 2 | use Dwarf::Pragma; | ||
| 3 | use Dwarf::Util qw/add_method/; | ||
| 4 | use File::Basename qw/dirname/; | ||
| 5 | use File::Path qw/make_path/; | ||
| 6 | use Log::Dispatch::FileRotate; | ||
| 7 | |||
| 8 | sub init { | ||
| 9 | my ($class, $c, $conf) = @_; | ||
| 10 | $conf ||= { | ||
| 11 | min_level => 'debug', | ||
| 12 | filename => $c->base_dir . '/log/dwarf.log', | ||
| 13 | mode => 'append', | ||
| 14 | TZ => 'Asia/Tokyo', | ||
| 15 | DatePattern => 'yyyy-MM-dd', | ||
| 16 | }; | ||
| 17 | |||
| 18 | $conf->{min_level} ||= 'debug'; | ||
| 19 | $conf->{filename} ||= $c->base_dir . '/log/dwarf_log'; | ||
| 20 | $conf->{mode} ||= 'append'; | ||
| 21 | |||
| 22 | unless (-f $conf->{filename}) { | ||
| 23 | my $dir = dirname($conf->{filename}); | ||
| 24 | make_path($dir, { mode => 0775 }) unless -d $dir; | ||
| 25 | } | ||
| 26 | |||
| 27 | $c->{'dwarf.log'} = Log::Dispatch::FileRotate->new(%$conf); | ||
| 28 | |||
| 29 | add_method($c, log => sub { | ||
| 30 | my $self = shift; | ||
| 31 | return $self->{'dwarf.log'}; | ||
| 32 | }); | ||
| 33 | |||
| 34 | add_method($c, debug => sub { | ||
| 35 | my $self = shift; | ||
| 36 | return unless @_; | ||
| 37 | my $message = join '', @_; | ||
| 38 | unless ($message =~ /\n$/) { | ||
| 39 | $message .= "\n"; | ||
| 40 | } | ||
| 41 | $self->{'dwarf.log'}->log(level => 'debug', message => $message); | ||
| 42 | }); | ||
| 43 | } | ||
| 44 | |||
| 45 | 1; |