This file is indexed.

/usr/share/perl5/Plack/Middleware/SimpleLogger.pm is in libplack-perl 1.0047-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
package Plack::Middleware::SimpleLogger;
use strict;
use parent qw(Plack::Middleware);
use Config ();
use Plack::Util::Accessor qw(level);
use POSIX ();
use Scalar::Util ();

# Should this be in Plack::Util?
my $i = 0;
my %level_numbers = map { $_ => $i++ } qw(debug info warn error fatal);

sub call {
    my($self, $env) = @_;

    my $min = $level_numbers{ $self->level || "debug" };

    my $env_ref = $env;
    Scalar::Util::weaken($env_ref);

    $env->{'psgix.logger'} = sub {
        my $args = shift;

        if ($level_numbers{$args->{level}} >= $min) {
            $env_ref->{'psgi.errors'}->print($self->format_message($args->{level}, $args->{message}));
        }
    };

    $self->app->($env);
}

sub format_time {
    my $old_locale;
    if ( $Config::config{d_setlocale} ) {
        $old_locale = POSIX::setlocale(&POSIX::LC_ALL);
        POSIX::setlocale(&POSIX::LC_ALL, 'C');
    }
    my $out = POSIX::strftime(@_);
    if ( $Config::config{d_setlocale} ) {
        POSIX::setlocale(&POSIX::LC_ALL, $old_locale);
    };
    return $out;
}

sub format_message {
    my($self, $level, $message) = @_;

    my $time = format_time("%Y-%m-%dT%H:%M:%S", localtime);
    sprintf "%s [%s #%d] %s: %s\n", uc substr($level, 0, 1), $time, $$, uc $level, $message;
}

1;

__END__

=head1 NAME

Plack::Middleware::SimpleLogger - Simple logger that prints to psgi.errors

=head1 SYNOPSIS

  enable "SimpleLogger", level => "warn";

=head1 DESCRIPTION

SimpleLogger is a middleware component that formats the log message
with information such as the time and PID and prints them to
I<psgi.errors> stream, which is mostly STDERR or server log output.

=head1 SEE ALSO

L<Plack::Middleware::LogErrors>, essentially the opposite of this module

=head1 AUTHOR

Tatsuhiko Miyagawa

=cut