eris

 view release on metacpan or  search on metacpan

lib/eris/log/context/caddy.pm  view on Meta::CPAN

use namespace::autoclean;
with qw(
    eris::role::context
);

our $VERSION = '0.009'; # VERSION


sub sample_messages {
    my @msgs = split /\r?\n/, <<'EOF';
Jul  4 23:37:51 app2 caddy[2140]: {"level":"info","ts":1751672271.1656768,"logger":"http.log.access.log7","msg":"handled request","request":{"remote_ip":"172.69.176.57","remote_port":"44552","client_ip":"172.69.176.57","proto":"HTTP/2.0","method":"GE...
Jul  4 23:37:52 app2 caddy[2140]: {"level":"info","ts":1751672272.5860772,"logger":"http.log.access.log7","msg":"handled request","request":{"remote_ip":"162.158.106.254","remote_port":"28088","client_ip":"162.158.106.254","proto":"HTTP/2.0","method"...
EOF
    return @msgs;
}


my %mapping = qw(
    method   action
    size     out_bytes
    status   status
);

sub contextualize_message {
    my ($self,$log) = @_;

    my $c = $log->context;

    my %ctx = ();
    if ( my $r = $c->{request} ) {
        $ctx{src_ip} = $r->{$_} for qw(remote_ip client_ip);
        if ( my $h = $r->{headers} ) {
            foreach my $k ( qw(X-Forwarded-For Cf-Connecting-Ip) ) {
                next unless $h->{$k};
                foreach my $v ( @{ $h->{$k} } ) {
                    $ctx{src_ip} = $v;
                }
            }
            if ( my $uas = $h->{'User-Agent'} ) {
                $ctx{prod} = $uas->[-1];
            }
        }



( run in 1.684 second using v1.01-cache-2.11-cpan-13bb782fe5a )