File::Stamped - time stamped log file
use File::Stamped; my $fh = File::Stamped->new(pattern => '/var/log/myapp.log.%Y%m%d.txt'); $fh->print("OK\n"); # with Log::Minimal use Log::Minimal; my $fh = File::Stamped->new(pattern => '/var/log/myapp.log.%Y%m%d.txt'); local $Log::Minimal::PRINT = sub { my ( $time, $type, $message, $trace) = @_; print {$fh} "$time [$type] $message at $trace\n"; };
File::Stamped is utility library for logging. File::Stamped object mimic file handle.
You can use "myapp.log.%Y%m%d.log" style log file.
This method creates new instance of File::Stamped. The arguments are followings.
You need to specify one of pattern or callback.
This is file name pattern. It is the pattern for filename. The format is POSIX::strftime(), see also POSIX.
You can use a CodeRef to generate file name.
File::Stamped pass only one arguments to callback function.
Here is a example code:
my $pattern = '/path/to/myapp.log.%Y%m%d.log'; my $f = File::Stamped->new(callback => sub { my $file_stamped = shift; local $_ = $pattern; s/!!/$$/ge; $_ = POSIX::strftime($_, localtime()); return $_; });
Default value is 1.
This is IO mode for opening file.
Default value is '>>:utf8'.
This attribute changes $|.
The time between log file generates in seconds. Default value is 1.
This method prints the $str to the file.
Tokuhiro Matsuno <tokuhirom AAJKLFJEF@ gmail.com>
Log::Dispatch::File::Stamped
Copyright (C) Tokuhiro Matsuno
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install File::Stamped, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::Stamped
CPAN shell
perl -MCPAN -e shell install File::Stamped
For more information on module installation, please visit the detailed CPAN module installation guide.