| 1 | package eris::log::context::static; | ||||||||||
| 2 | # ABSTRACT: Add static keys/values to every message | ||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Types::Standard qw(HashRef Maybe); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | with qw( | |||||||||
| 8 | eris::role::context | ||||||||||
| 9 | ); | ||||||||||
| 10 | |||||||||||
| 11 | 1 | our $VERSION = '0.008'; # VERSION | |||||||||
| 12 | |||||||||||
| 13 | 1 | our $SuppressWarnings = 1; | |||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub _build_field { '*' } | ||||||||
|
Subroutine
_build_field: not called CC=1 SCAR=6.9
| |||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | 0 | ▶ | sub _build_matcher { '*' } | ||||||||
|
Subroutine
_build_matcher: not called CC=1 SCAR=6.9
| |||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | has 'fields' => ( | ||||||||||
| 23 | is => 'rw', | ||||||||||
| 24 | isa => HashRef, | ||||||||||
| 25 | 0 | ▶ | default => sub { 'disable loading' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 26 | 1 | ); | |||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | sub sample_messages { | ||||||||||
| 30 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
sample_messages: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 31 | #$self->fields({ subject => 'testing', source => 'testing' }); | ||||||||||
| 32 | 0 | my @msgs = split /\r?\n/, <<'EOF'; | |||||||||
| 33 | Sep 10 19:59:05 ether sudo: brad : TTY=pts/5 ; PWD=/home/brad ; USER=root ; COMMAND=/bin/grep -i sudo /var/log/secure | ||||||||||
| 34 | EOF | ||||||||||
| 35 | 0 | return @msgs; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | sub contextualize_message { | ||||||||||
| 40 | 0 | ▶ | my ($self,$log) = @_; | ||||||||
|
Subroutine
contextualize_message: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 41 | # Simply add the fields | ||||||||||
| 42 | 0 | ▶ | $log->add_context(static => $self->fields) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | if $self->fields; | ||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | 1 | 1; | |||||||||
| 48 | |||||||||||
| 49 | __END__ | ||||||||||
| 50 | |||||||||||
| 51 | =pod | ||||||||||
| 52 | |||||||||||
| 53 | =encoding UTF-8 | ||||||||||
| 54 | |||||||||||
| 55 | =head1 NAME | ||||||||||
| 56 | |||||||||||
| 57 | eris::log::context::static - Add static keys/values to every message | ||||||||||
| 58 | |||||||||||
| 59 | =head1 VERSION | ||||||||||
| 60 | |||||||||||
| 61 | version 0.008 | ||||||||||
| 62 | |||||||||||
| 63 | =head1 SYNOPSIS | ||||||||||
| 64 | |||||||||||
| 65 | This context exists to statically add key/value pairs to every message. | ||||||||||
| 66 | |||||||||||
| 67 | =head1 ATTRIBUTES | ||||||||||
| 68 | |||||||||||
| 69 | =head2 field | ||||||||||
| 70 | |||||||||||
| 71 | Set to C<*> | ||||||||||
| 72 | |||||||||||
| 73 | =head2 matcher | ||||||||||
| 74 | |||||||||||
| 75 | Set to C<*> | ||||||||||
| 76 | |||||||||||
| 77 | This combo causes this to match every message. | ||||||||||
| 78 | |||||||||||
| 79 | =head2 fields | ||||||||||
| 80 | |||||||||||
| 81 | A HashRef of keys/values to add to every message. To configure: | ||||||||||
| 82 | |||||||||||
| 83 | --- | ||||||||||
| 84 | contexts: | ||||||||||
| 85 | config: | ||||||||||
| 86 | static: | ||||||||||
| 87 | fields: | ||||||||||
| 88 | dc: DCA1 | ||||||||||
| 89 | env: prod | ||||||||||
| 90 | |||||||||||
| 91 | =head1 METHODS | ||||||||||
| 92 | |||||||||||
| 93 | =head2 contextualize_message | ||||||||||
| 94 | |||||||||||
| 95 | If configured, this context just takes the fields specified in it's config and | ||||||||||
| 96 | adds those fields to every message. | ||||||||||
| 97 | |||||||||||
| 98 | =for Pod::Coverage sample_messages | ||||||||||
| 99 | |||||||||||
| 100 | =head1 SEE ALSO | ||||||||||
| 101 | |||||||||||
| 102 | L<eris::log::contextualizer>, L<eris::role::context> | ||||||||||
| 103 | |||||||||||
| 104 | =head1 AUTHOR | ||||||||||
| 105 | |||||||||||
| 106 | Brad Lhotsky <brad@divisionbyzero.net> | ||||||||||
| 107 | |||||||||||
| 108 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 109 | |||||||||||
| 110 | This software is Copyright (c) 2015 by Brad Lhotsky. | ||||||||||
| 111 | |||||||||||
| 112 | This is free software, licensed under: | ||||||||||
| 113 | |||||||||||
| 114 | The (three-clause) BSD License | ||||||||||
| 115 | |||||||||||
| 116 | =cut | ||||||||||