File: log-as-csv-string.pl

package info (click to toggle)
liblog-handler-perl 0.90-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 576 kB
  • sloc: perl: 2,758; makefile: 4
file content (27 lines) | stat: -rw-r----- 552 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl
use strict;
use warnings;
use Log::Handler;
use Text::CSV;

my $log = Log::Handler->new();
my $csv = Text::CSV->new();

$log->add(
    screen => {
        maxlevel        => 'info',
        newline         => 1,
        message_layout  => '%m',
        message_pattern => '%T %L %P %t',
        prepare_message => sub {
            my $m = shift;
            $csv->combine(@{$m}{qw/time level pid mtime message/});
            $m->{message} = $csv->string;
        },
    }
);

$log->info('foo');
$log->info('bar');
$log->info('baz');