| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Mojo::Log::Colored; | 
| 2 | 3 |  |  | 3 |  | 387696 | use Mojo::Base 'Mojo::Log'; | 
|  | 3 |  |  |  |  | 15483 |  | 
|  | 3 |  |  |  |  | 21 |  | 
| 3 | 3 |  |  | 3 |  | 217291 | use Term::ANSIColor 'colored'; | 
|  | 3 |  |  |  |  | 18544 |  | 
|  | 3 |  |  |  |  | 1145 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 3 |  |  | 3 |  | 1973 | use if $^O eq "MSWin32", "Win32::Console::ANSI"; | 
|  | 3 |  |  |  |  | 51 |  | 
|  | 3 |  |  |  |  | 19 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = "0.02"; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | has 'colors' => sub { | 
| 10 |  |  |  |  |  |  | return { | 
| 11 |  |  |  |  |  |  | debug => "bold bright_white", | 
| 12 |  |  |  |  |  |  | info  => "bold bright_blue", | 
| 13 |  |  |  |  |  |  | warn  => "bold green", | 
| 14 |  |  |  |  |  |  | error => "bold yellow", | 
| 15 |  |  |  |  |  |  | fatal => "bold yellow on_red", | 
| 16 |  |  |  |  |  |  | }; | 
| 17 |  |  |  |  |  |  | }; | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | has _format => sub { | 
| 20 |  |  |  |  |  |  | shift->format( \&_default_format ); | 
| 21 |  |  |  |  |  |  | }; | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | sub format { | 
| 24 | 48 | 100 |  | 48 | 1 | 108217 | return $_[0]->_format if @_ == 1; | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 8 |  |  |  |  | 34 | my ( $self, $format ) = @_; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | return $self->_format( | 
| 29 |  |  |  |  |  |  | sub { | 
| 30 |  |  |  |  |  |  | # only add colors if we have a color for this level | 
| 31 |  |  |  |  |  |  | exists $self->colors->{ $_[1] } | 
| 32 | 40 | 100 |  | 40 |  | 264 | ? colored( $format->(@_), $self->colors->{ $_[1] } ) | 
| 33 |  |  |  |  |  |  | : $format->(@_); | 
| 34 |  |  |  |  |  |  | } | 
| 35 | 8 |  |  |  |  | 93 | )->_format; | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | sub _default_format { | 
| 39 | 5 |  |  | 5 |  | 419 | '[' . localtime(shift) . '] [' . shift() . '] ' . join "\n", @_, ''; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | 1; | 
| 43 |  |  |  |  |  |  | __END__ |