File: structured-logging.t

package info (click to toggle)
liblog-any-perl 1.717-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 448 kB
  • sloc: perl: 1,499; makefile: 11
file content (71 lines) | stat: -rw-r--r-- 1,981 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;
use Test::More tests => 2;

use Log::Any::Adapter;
use Log::Any '$log';

use FindBin;
use lib $FindBin::RealBin;
use TestAdapters;

sub create_normal_log_lines {
    my ($log) = @_;

    $log->info('some info');
    $log->infof( 'more %s', 'info' );
    $log->infof( 'info %s %s', { with => 'data' }, 'and more text' );
    $log->debug( "program started",
        { progname => "foo.pl", pid => 1234, perl_version => "5.20.0" } );

}

Log::Any::Adapter->set('+TestAdapters::Normal');
create_normal_log_lines($log);

Log::Any::Adapter->set('+TestAdapters::Structured');
create_normal_log_lines($log);
$log->info(
    'text',
    { and => [ 'structured', 'data', of => [ arbitrary => 'depth' ] ] },
    'and some more text'
);

is_deeply(
    \@TestAdapters::TEXT_LOG, [

        "some info",
        "more info",
        "info {with => \"data\"} and more text",
        "program started {perl_version => \"5.20.0\",pid => 1234,progname => \"foo.pl\"}"
    ],
    'text log correct'
);

is_deeply(
    \@TestAdapters::STRUCTURED_LOG,
    [   { messages => ['some info'], level => 'info', category => 'main' },
        { messages => ['more info'], level => 'info', category => 'main' },
        { messages => ['info {with => "data"} and more text'],
          level    => 'info',
          category => 'main'
        },
        {   messages => ['program started'],
            level    => 'debug',
            category => 'main',
            data     => [
                { perl_version => "5.20.0", progname => "foo.pl", pid => 1234 }
                ]
        },
        {   messages => [ 'text', 'and some more text' ],
            data     => [
                {   and =>
                        [ 'structured', 'data', of => [ arbitrary => 'depth' ] ]
                }
                ],
            level    => 'info',
            category => 'main'
        }
    ],
    'identical output of normal log lines when using structured log adapter'
    );