| 1 | 1 | ▶ | use strictures 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | |||||||||||
| 3 | package Dancer2::Logger::Radis; | ||||||||||
| 4 | |||||||||||
| 5 | # ABSTRACT: Dancer2 logger engine for Log::Radis | ||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use Moo 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Log::Radis 0.002; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use FindBin qw($RealBin $RealScript); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | my $BIN = "$RealBin/$RealScript"; | |||||||||
| 13 | |||||||||||
| 14 | 1 | with 'Dancer2::Core::Role::Logger'; | |||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | 1 | our $VERSION = '0.002'; # VERSION | |||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | 1 | has server => ( | |||||||||
| 21 | is => 'ro', | ||||||||||
| 22 | default => 'localhost:6379', | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | 1 | has reconnect => ( | |||||||||
| 27 | is => 'ro', | ||||||||||
| 28 | default => 5, | ||||||||||
| 29 | ); | ||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | 1 | has every => ( | |||||||||
| 33 | is => 'ro', | ||||||||||
| 34 | default => 1, | ||||||||||
| 35 | ); | ||||||||||
| 36 | |||||||||||
| 37 | |||||||||||
| 38 | 1 | has queue => ( | |||||||||
| 39 | is => 'ro', | ||||||||||
| 40 | default => 'graylog-radis:queue', | ||||||||||
| 41 | ); | ||||||||||
| 42 | |||||||||||
| 43 | |||||||||||
| 44 | 1 | has __mock => ( | |||||||||
| 45 | is => 'ro', | ||||||||||
| 46 | ); | ||||||||||
| 47 | |||||||||||
| 48 | has _radis => ( | ||||||||||
| 49 | is => 'lazy', | ||||||||||
| 50 | builder => sub | ||||||||||
| 51 | 1 | ▶ | { | ||||||||
|
Subroutine
_build__radis: called CC=2 SCAR=7.0
| |||||||||||
| 52 | 1 | my $self = shift; | |||||||||
| 53 | 1 | my %opts = ( | |||||||||
| 54 | server => $self->server, | ||||||||||
| 55 | reconnect => $self->reconnect, | ||||||||||
| 56 | every => $self->every, | ||||||||||
| 57 | queue => $self->queue, | ||||||||||
| 58 | ); | ||||||||||
| 59 | 1 | ▶ | if ($self->__mock) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 1 | $opts{redis} = $self->__mock; | |||||||||
| 61 | } | ||||||||||
| 62 | 1 | Log::Radis->new(%opts); | |||||||||
| 63 | } | ||||||||||
| 64 | 1 | ); | |||||||||
| 65 | |||||||||||
| 66 | sub _dump | ||||||||||
| 67 | 3 | ▶ | { | ||||||||
|
Subroutine
_dump: called CC=1 SCAR=0.0
| |||||||||||
| 68 | 3 | Data::Dumper->new(\@_)->Terse(1)->Purity(1)->Indent(0)->Sortkeys(1)->Dump() | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | sub _serialize | ||||||||||
| 72 | 16 | ▶ | { | ||||||||
|
Subroutine
_serialize: called CC=2 SCAR=6.9
| |||||||||||
| 73 | 16 | ▶ | map { ref $_ ? _dump($_) : $_ } @_ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | |||||||||||
| 77 | sub log | ||||||||||
| 78 | 10 | ▶ | { | ||||||||
|
Subroutine
log: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 79 | 10 | my $self = shift; | |||||||||
| 80 | 10 | my ($level, @args) = @_; | |||||||||
| 81 | 10 | my ($message, %extras) = map { _serialize($_) } @args; | |||||||||
| 82 | |||||||||||
| 83 | |||||||||||
| 84 | my %gelf = ( | ||||||||||
| 85 | _source => $self->app_name, | ||||||||||
| 86 | _pid => $$, | ||||||||||
| 87 | _bin => $BIN, | ||||||||||
| 88 | 10 | map {( '_dancer_'.lc($_) => $extras{$_} )} keys %extras | |||||||||
| 89 | ); | ||||||||||
| 90 | |||||||||||
| 91 | 10 | ▶ | if (my $request = $self->request) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 5 | $gelf{_http_id} = $request->id; | |||||||||
| 93 | 5 | $gelf{_http_user} = $request->user; | |||||||||
| 94 | 5 | $gelf{_http_client} = $request->address; | |||||||||
| 95 | 5 | $gelf{_http_method} = $request->method; | |||||||||
| 96 | 5 | $gelf{_http_path} = $request->path; | |||||||||
| 97 | 5 | $gelf{_http_proto} = $request->protocol; | |||||||||
| 98 | 5 | $gelf{_http_referer} = $request->header('referer'); | |||||||||
| 99 | 5 | $gelf{_http_useragent} = $request->header('user_agent'); | |||||||||
| 100 | 5 | ▶ | if ($self->has_session) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | 0 | $gelf{_session_id} = $request->session->id; | |||||||||
| 102 | } | ||||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | 10 | $self->_radis->log($level, $message, %gelf); | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | |||||||||||
| 109 | 5 | ▶ | sub core { @_ = (shift, 'core', @_); goto &log } | ||||||||
|
Subroutine
core: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 110 | 1 | ▶ | sub debug { @_ = (shift, 'debug', @_); goto &log } | ||||||||
|
Subroutine
debug: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 111 | 2 | ▶ | sub info { @_ = (shift, 'info', @_); goto &log } | ||||||||
|
Subroutine
info: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 112 | 1 | ▶ | sub warning { @_ = (shift, 'warning', @_); goto &log } | ||||||||
|
Subroutine
warning: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 113 | 1 | ▶ | sub error { @_ = (shift, 'error', @_); goto &log } | ||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 114 | |||||||||||
| 115 | 1 | 1; | |||||||||
| 116 | |||||||||||
| 117 | __END__ | ||||||||||