/usr/share/perl5/Protocol/HTTP2/Trace.pm is in libprotocol-http2-perl 1.08-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 | package Protocol::HTTP2::Trace;
use strict;
use warnings;
use Time::HiRes qw(time);
use Exporter qw(import);
our @EXPORT_OK = qw(tracer bin2hex);
my %levels = (
debug => 0,
info => 1,
notice => 2,
warning => 3,
error => 4,
critical => 5,
alert => 6,
emergency => 7,
);
my $tracer_sngl = Protocol::HTTP2::Trace->_new(
min_level =>
( exists $ENV{HTTP2_DEBUG} && exists $levels{ $ENV{HTTP2_DEBUG} } )
? $levels{ $ENV{HTTP2_DEBUG} }
: $levels{error}
);
my $start_time = 0;
sub tracer {
$tracer_sngl;
}
sub _new {
my ( $class, %opts ) = @_;
bless {%opts}, $class;
}
sub _log {
my ( $self, $level, $message ) = @_;
$level = uc($level);
chomp($message);
my $now = time;
if ( $now - $start_time < 60 ) {
$message =~ s/\n/\n /g;
printf "[%05.3f] %s %s\n", $now - $start_time, $level, $message;
}
else {
my @t = ( localtime() )[ 5, 4, 3, 2, 1, 0 ];
$t[0] += 1900;
$t[1]++;
$message =~ s/\n/\n /g;
printf "[%4d-%02d-%02d %02d:%02d:%02d] %s %s\n", @t, $level, $message;
$start_time = $now;
}
}
{
no strict 'refs';
for my $l ( keys %levels ) {
*{ __PACKAGE__ . "::" . $l } =
( $levels{$l} >= $tracer_sngl->{min_level} )
? sub {
shift->_log( $l, @_ );
}
: sub { 1 }
}
}
sub bin2hex {
my $bin = shift;
my $c = 0;
my $s;
join "", map {
$c++;
$s = !( $c % 16 ) ? "\n" : ( $c % 2 ) ? "" : " ";
$_ . $s
} unpack( "(H2)*", $bin );
}
1;
|