| 1 | package eris::log::contextualizer; | ||||||||||
| 2 | # ABSTRACT: Primary interface to the eris log parsing library | ||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Time::HiRes qw(gettimeofday tv_interval); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Types::Standard qw( HashRef InstanceOf ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use eris::log::contexts; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use eris::log::decoders; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | our $VERSION = '0.008'; # VERSION | |||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | has config => ( | ||||||||||
| 17 | is => 'ro', | ||||||||||
| 18 | isa => HashRef, | ||||||||||
| 19 | 0 | ▶ | default => sub { +{} }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 20 | 1 | ); | |||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | 1 | has contexts => ( | |||||||||
| 25 | is => 'ro', | ||||||||||
| 26 | isa => InstanceOf['eris::log::contexts'], | ||||||||||
| 27 | handles => [qw(contextualize)], | ||||||||||
| 28 | lazy => 1, | ||||||||||
| 29 | builder => '_build_contexts', | ||||||||||
| 30 | ); | ||||||||||
| 31 | sub _build_contexts { | ||||||||||
| 32 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build_contexts: not called CC=2 SCAR=17.9
| |||||||||||
| 33 | return eris::log::contexts->new( | ||||||||||
| 34 | 0 | ▶ | %{ $self->config->{contexts} || {} }, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | ); | ||||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | 1 | has 'decoders' => ( | |||||||||
| 40 | is => 'ro', | ||||||||||
| 41 | isa => InstanceOf['eris::log::decoders'], | ||||||||||
| 42 | handles => [qw(decode)], | ||||||||||
| 43 | lazy => 1, | ||||||||||
| 44 | builder => '_build_decoders', | ||||||||||
| 45 | handles => [qw(decode)], | ||||||||||
| 46 | ); | ||||||||||
| 47 | sub _build_decoders { | ||||||||||
| 48 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build_decoders: not called CC=2 SCAR=17.9
| |||||||||||
| 49 | return eris::log::decoders->new( | ||||||||||
| 50 | 0 | ▶ | %{ $self->config->{decoders} || {} }, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | ); | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | |||||||||||
| 55 | sub parse { | ||||||||||
| 56 | 0 | ▶ | my ($self,$raw) = @_; | ||||||||
|
Subroutine
parse: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 57 | |||||||||||
| 58 | # Apply the decoders | ||||||||||
| 59 | 0 | my %t=(); | |||||||||
| 60 | 0 | my $t0 = [gettimeofday]; | |||||||||
| 61 | 0 | my $log = $self->decode($raw); | |||||||||
| 62 | 0 | $log->add_context( raw => { raw => $raw } ); | |||||||||
| 63 | 0 | my $tdiff = tv_interval($t0); | |||||||||
| 64 | 0 | $t{decoders} = $tdiff; | |||||||||
| 65 | |||||||||||
| 66 | # Add context | ||||||||||
| 67 | 0 | my $t1 = [gettimeofday]; | |||||||||
| 68 | 0 | $self->contextualize($log); | |||||||||
| 69 | 0 | my $t2 = [gettimeofday]; | |||||||||
| 70 | |||||||||||
| 71 | # Record timings | ||||||||||
| 72 | 0 | $t{contexts} = tv_interval( $t1, $t2 ); | |||||||||
| 73 | 0 | $t{total} = tv_interval( $t0, $t2 ); | |||||||||
| 74 | 0 | $log->add_timing(%t); | |||||||||
| 75 | |||||||||||
| 76 | # Return the log created | ||||||||||
| 77 | 0 | return $log; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | |||||||||||
| 81 | 1 | 1; | |||||||||
| 82 | |||||||||||
| 83 | __END__ | ||||||||||
| 84 | |||||||||||
| 85 | =pod | ||||||||||
| 86 | |||||||||||
| 87 | =encoding UTF-8 | ||||||||||
| 88 | |||||||||||
| 89 | =head1 NAME | ||||||||||
| 90 | |||||||||||
| 91 | eris::log::contextualizer - Primary interface to the eris log parsing library | ||||||||||
| 92 | |||||||||||
| 93 | =head1 VERSION | ||||||||||
| 94 | |||||||||||
| 95 | version 0.008 | ||||||||||
| 96 | |||||||||||
| 97 | =head1 SYNOPSIS | ||||||||||
| 98 | |||||||||||
| 99 | This objects wraps the decoders and contexts to fully annotate an L<eris::log> | ||||||||||
| 100 | instance. | ||||||||||
| 101 | |||||||||||
| 102 | use Data::Printer; | ||||||||||
| 103 | use eris::contextualizer; | ||||||||||
| 104 | |||||||||||
| 105 | my $ctxr = eris::contextualizer->new(); | ||||||||||
| 106 | |||||||||||
| 107 | while( <<>> ) { | ||||||||||
| 108 | p( $ctxr->parse($_) ) | ||||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | =head1 ATTRIBUTES | ||||||||||
| 112 | |||||||||||
| 113 | =head2 config | ||||||||||
| 114 | |||||||||||
| 115 | The configuration as a hash reference. | ||||||||||
| 116 | |||||||||||
| 117 | A YAML Representation of the root namespaces for the configuration: | ||||||||||
| 118 | |||||||||||
| 119 | --- | ||||||||||
| 120 | contexts: {} | ||||||||||
| 121 | decoders: {} | ||||||||||
| 122 | schemas: {} | ||||||||||
| 123 | |||||||||||
| 124 | =head2 contexts | ||||||||||
| 125 | |||||||||||
| 126 | An instance of an L<eris::log::contexts> object. Passed | ||||||||||
| 127 | the configuration specified in the C<contexts> root key of | ||||||||||
| 128 | the config or an empty HashRef | ||||||||||
| 129 | |||||||||||
| 130 | =head2 decoders | ||||||||||
| 131 | |||||||||||
| 132 | An instance of an L<eris::log::decoders> object. Passed | ||||||||||
| 133 | the configuration specified in the C<decoders> root key of | ||||||||||
| 134 | the config or an empty HashRef | ||||||||||
| 135 | |||||||||||
| 136 | =head1 METHODS | ||||||||||
| 137 | |||||||||||
| 138 | =head2 parse | ||||||||||
| 139 | |||||||||||
| 140 | Takes a raw string. | ||||||||||
| 141 | |||||||||||
| 142 | Builds the list of decoders and contexts, passes the raw string to | ||||||||||
| 143 | the L<eris::log::decoders>, which returns an instance of an L<eris::log> object. | ||||||||||
| 144 | |||||||||||
| 145 | Then calls L<eris::log::contexts>, passing that L<eris::log> instance to each. | ||||||||||
| 146 | |||||||||||
| 147 | This method wraps this process w/timing data that's added with the | ||||||||||
| 148 | L<eris::log>'s C<add_timing> method. This data is available when the | ||||||||||
| 149 | L<eris::dictionary::eris::debug> is enabled. This can be helpful for examining | ||||||||||
| 150 | parser performance. | ||||||||||
| 151 | |||||||||||
| 152 | =head1 SEE ALSO | ||||||||||
| 153 | |||||||||||
| 154 | L<eris::log>, L<eris::log::decoders>, L<eris::log::contexts> | ||||||||||
| 155 | |||||||||||
| 156 | =head1 AUTHOR | ||||||||||
| 157 | |||||||||||
| 158 | Brad Lhotsky <brad@divisionbyzero.net> | ||||||||||
| 159 | |||||||||||
| 160 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 161 | |||||||||||
| 162 | This software is Copyright (c) 2015 by Brad Lhotsky. | ||||||||||
| 163 | |||||||||||
| 164 | This is free software, licensed under: | ||||||||||
| 165 | |||||||||||
| 166 | The (three-clause) BSD License | ||||||||||
| 167 | |||||||||||
| 168 | =cut | ||||||||||