/usr/share/perl5/Dancer/Logger/File.pm is in libdancer-perl 1.3202+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | package Dancer::Logger::File;
our $AUTHORITY = 'cpan:SUKRIA';
#ABSTRACT: file-based logging engine for Dancer
$Dancer::Logger::File::VERSION = '1.3202';
use strict;
use warnings;
use Carp;
use base 'Dancer::Logger::Abstract';
use Dancer::Config 'setting';
use Dancer::FileUtils qw(open_file);
use IO::File;
use Fcntl qw(:flock SEEK_END);
sub logdir {
if ( my $altpath = setting('log_path') ) {
return $altpath;
}
my $logroot = setting('appdir');
if ( $logroot and ! -d $logroot and ! mkdir $logroot ) {
carp "app directory '$logroot' doesn't exist, am unable to create it";
return;
}
my $expected_path = $logroot ?
Dancer::FileUtils::path($logroot, 'logs') :
Dancer::FileUtils::path('logs');
return $expected_path if -d $expected_path && -x _ && -w _;
unless (-w $logroot and -x _) {
my $perm = (stat $logroot)[2] & 07777;
chmod($perm | 0700, $logroot);
unless (-w $logroot and -x _) {
carp "app directory '$logroot' isn't writable/executable and can't chmod it";
return;
}
}
return $expected_path;
}
sub init {
my $self = shift;
$self->SUPER::init(@_);
my $logdir = logdir();
return unless ($logdir);
my $logfile = setting('log_file') || setting('environment').".log";
mkdir($logdir) unless(-d $logdir);
$logfile = File::Spec->catfile($logdir, $logfile);
my $fh;
unless($fh = open_file('>>', $logfile)) {
carp "unable to create or append to $logfile";
return;
}
# looks like older perls don't auto-convert to IO::File
# and can't autoflush
# see https://github.com/PerlDancer/Dancer/issues/954
eval { $fh->autoflush };
$self->{logfile} = $logfile;
$self->{fh} = $fh;
}
sub _log {
my ($self, $level, $message) = @_;
my $fh = $self->{fh};
return unless(ref $fh && $fh->opened);
flock($fh, LOCK_EX)
or carp "locking logfile $self->{logfile} failed";
seek($fh, 0, SEEK_END)
or carp "seeking to logfile $self->{logfile} end failed";
$fh->print($self->format_message($level => $message))
or carp "writing to logfile $self->{logfile} failed";
flock($fh, LOCK_UN)
or carp "unlocking logfile $self->{logfile} failed";
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Dancer::Logger::File - file-based logging engine for Dancer
=head1 VERSION
version 1.3202
=head1 SYNOPSIS
=head1 DESCRIPTION
This is a file-based logging engine that allows you to save your logs to files
on disk.
=head1 METHODS
=head2 init
This method is called when C<< ->new() >> is called. It initializes the log
directory, creates if it doesn't already exist and opens the designated log
file.
=head2 logdir
Returns the log directory, decided by "logs" either in "appdir" setting.
It's also possible to specify a logs directory with the log_path option.
setting log_path => $dir;
=head2 _log
Writes the log message to the file.
=head1 AUTHOR
Dancer Core Developers
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Alexis Sukrieh.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|