blib/lib/WebService/Mattermost/Util/Logger.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 20 | 20 | 100.0 |
branch | 1 | 2 | 50.0 |
condition | n/a | ||
subroutine | 9 | 9 | 100.0 |
pod | n/a | ||
total | 30 | 31 | 96.7 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package WebService::Mattermost::Util::Logger; 2: 3: # ABSTRACT: Internal logger. 4: 5: use Moo; 6: use Mojo::Util 'monkey_patch'; 7: use Mojo::Log; 8: use Types::Standard 'InstanceOf'; 9: 10: ################################################################################ 11: 12: has logger => (is => 'ro', isa => InstanceOf['Mojo::Log'], lazy => 1, builder => 1); 13: 14: has logger_store => (is => 'rw', isa => InstanceOf['Mojo::Log']); 15: 16: ################################################################################ 17: 18: monkey_patch 'Mojo::Log', 19: debugf => sub { shift->debug(sprintf shift, @_) }, 20: infof => sub { shift->info(sprintf shift, @_) }, 21: fatalf => sub { shift->fatal(sprintf shift, @_) }, 22: warnf => sub { shift->warn(sprintf shift, @_) }; 23: 24: ################################################################################ 25: 26: sub _build_logger { 27: my $self = shift; 28: 29: unless ($self->logger_store) { 30: $self->logger_store(Mojo::Log->new()); 31: } 32: 33: return $self->logger_store; 34: } 35: 36: ################################################################################ 37: 38: 1; 39: 40: __END__ 41: 42: =pod 43: 44: =encoding UTF-8 45: 46: =head1 NAME 47: 48: WebService::Mattermost::Util::Logger - Internal logger. 49: 50: =head1 VERSION 51: 52: version 0.28 53: 54: =head1 DESCRIPTION 55: 56: Patched instance of C<Mojo::Log> with some wrapping methods. 57: 58: =head2 ATTRIBUTES 59: 60: =over 4 61: 62: =item C<logger> 63: 64: A C<Mojo::Log> object with additional methods: 65: 66: =over 8 67: 68: =item C<debugf()> 69: 70: $self->logger->debugf('sprintf for %s', 'debug'); # sprintf for debug 71: 72: =item C<infof()> 73: 74: $self->logger->infof('sprintf for %s', 'info'); # sprintf for info 75: 76: =item C<fatalf()> 77: 78: $self->logger->fatalf('sprintf for %s', 'fatal'); # sprintf for fatal 79: 80: =item C<warnf()> 81: 82: $self->logger->warnf('sprintf for %s', 'warn'); # sprintf for warn 83: 84: =back 85: 86: =back 87: 88: =head1 AUTHOR 89: 90: Mike Jones <mike@netsplit.org.uk> 91: 92: =head1 COPYRIGHT AND LICENSE 93: 94: This software is Copyright (c) 2020 by Mike Jones. 95: 96: This is free software, licensed under: 97: 98: The MIT (X11) License 99: 100: =cut 101: |