| 1 | package Log::Log4perl::Appender::Chunk::Store::File; | ||||||||||
| 2 | 2 | $Log::Log4perl::Appender::Chunk::Store::File::VERSION = '0.013'; | |||||||||
| 3 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | extends qw/Log::Log4perl::Appender::Chunk::Store/; | |||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use Log::Log4perl; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use File::Path (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use File::Spec (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use File::Temp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 2 | my $LOGGER = Log::Log4perl->get_logger(); | |||||||||
| 12 | |||||||||||
| 13 | 0 | ▶ | has 'base_directory' => ( is => 'ro' , isa => 'Str' , default => sub { File::Temp::tempdir() }); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 14 | 0 | ▶ | has 'log_folder' => ( is => 'ro' , isa => 'Str' , default => sub{ {'Log4perl_Appender_Chunk_Store_File'}; }); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||
| 15 | |||||||||||
| 16 | 2 | has '_logging_folder' => ( is => 'ro' , lazy_build => 1 ); | |||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | sub _build__logging_folder { | ||||||||
|
Subroutine
_build__logging_folder: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | my ($self)= @_; | |||||||||
| 20 | 1 | return File::Spec->catfile($self->base_directory, $self->log_folder) | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | sub store{ | ||||||||
|
Subroutine
store: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||
| 24 | 1 | my ($self, $chunk_id, $big_message) = @_; | |||||||||
| 25 | 1 | my $logging_dir = $self->_logging_folder(); | |||||||||
| 26 | 1 | ▶ | unless ( -d $logging_dir ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 1 | eval { File::Path::mkpath($logging_dir) }; | |||||||||
| 28 | 1 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | $LOGGER->trace("Couldn't create $logging_dir: $@"); | |||||||||
| 30 | 0 | return; | |||||||||
| 31 | } | ||||||||||
| 32 | } | ||||||||||
| 33 | 1 | my $chunk_log_file = File::Spec->catfile($logging_dir, $chunk_id); | |||||||||
| 34 | 1 | $LOGGER->info("Stored log chunk in $chunk_log_file"); | |||||||||
| 35 | |||||||||||
| 36 | 1 | File::Slurp::write_file( | |||||||||
| 37 | $chunk_log_file, | ||||||||||
| 38 | {binmode => ':utf8'}, | ||||||||||
| 39 | $big_message | ||||||||||
| 40 | ); | ||||||||||
| 41 | 1 | return 1; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 2 | __PACKAGE__->meta->make_immutable(); | |||||||||
| 45 | 2 | 1; | |||||||||
| 46 | __END__ | ||||||||||