.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Log::Dispatch::Dir 3pm" .TH Log::Dispatch::Dir 3pm "2014-05-17" "perl v5.18.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Log::Dispatch::Dir \- Log messages to separate files in a directory, with rotate options .SH "VERSION" .IX Header "VERSION" This document describes version 0.12 of Log::Dispatch::Dir (from Perl distribution Log-Dispatch-Dir), released on 2014\-05\-17. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Log::Dispatch::Dir; \& \& my $dir = Log::Dispatch::Dir\->new( \& name => \*(Aqdir1\*(Aq, \& min_level => \*(Aqinfo\*(Aq, \& dirname => \*(Aqsomedir.log\*(Aq, \& filename_pattern => \*(Aq%Y\-%m\-%d\-%H%M%S.%{ext}\*(Aq, \& ); \& $dir\->log( level => \*(Aqinfo\*(Aq, message => \*(Aqyour comment\en" ); \& \& # limit total size \& my $dir = Log::Dispatch::Dir\->new( \& # ... \& max_size => 10*1024*1024, # 10MB \& ); \& \& # limit number of files \& my $dir = Log::Dispatch::Dir\->new( \& # ... \& max_files => 1000, \& ); \& \& # limit oldest file \& my $dir = Log::Dispatch::Dir\->new( \& # ... \& max_age => 10*24*3600, # 10 days \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides a simple object for logging to directories under the Log::Dispatch::* system, and automatically rotating them according to different constraints. Each message will be logged to a separate file the directory. .PP Logging to separate files can be useful for example when dumping whole network responses (like HTTP::Response content). .SH "METHODS" .IX Header "METHODS" .SS "new(%p)" .IX Subsection "new(%p)" This method takes a hash of parameters. The following options are valid: .IP "\(bu" 4 name ($) .Sp The name of the object (not the dirname!). Required. .IP "\(bu" 4 min_level ($) .Sp The minimum logging level this object will accept. See the Log::Dispatch documentation on Log Levels for more information. Required. .IP "\(bu" 4 max_level ($) .Sp The maximum logging level this obejct will accept. See the Log::Dispatch documentation on Log Levels for more information. This is not required. By default the maximum is the highest possible level (which means functionally that the object has no maximum). .IP "\(bu" 4 dirname ($) .Sp The directory to write to. .IP "\(bu" 4 permissions ($) .Sp If the directory does not already exist, the permissions that it should be created with. Optional. The argument passed must be a valid octal value, such as 0700 or the constants available from Fcntl, like S_IRUSR|S_IWUSR|S_IXUSR. .Sp See \*(L"chmod\*(R" in perlfunc for more on potential traps when passing octal values around. Most importantly, remember that if you pass a string that looks like an octal value, like this: .Sp .Vb 1 \& my $mode = \*(Aq0644\*(Aq; .Ve .Sp Then the resulting directory will end up with permissions like this: .Sp .Vb 1 \& \-\-w\-\-\-\-r\-T .Ve .Sp which is probably not what you want. .IP "\(bu" 4 callbacks( \e& or [ \e&, \e&, ... ] ) .Sp This parameter may be a single subroutine reference or an array reference of subroutine references. These callbacks will be called in the order they are given and passed a hash containing the following keys: .Sp .Vb 1 \& ( message => $log_message, level => $log_level ) .Ve .Sp The callbacks are expected to modify the message and then return a single scalar containing that modified message. These callbacks will be called when either the \&\f(CW\*(C`log\*(C'\fR or \f(CW\*(C`log_to\*(C'\fR methods are called and will only be applied to a given message once. .IP "\(bu" 4 filename_pattern ($) .Sp Names to give to each file, expressed in pattern a la \fIstrftime()\fR's. Optional. Default is '%Y\-%m\-%d\-%H%M%S.pid\-%{pid}.%{ext}'. Time is expressed in local time. .Sp If file of the same name already exists, a suffix \*(L".1\*(R", \*(L".2\*(R", and so on will be appended. .Sp Available pattern: .RS 4 .ie n .IP "%Y \- 4\-digit year number, e.g. 2009" 8 .el .IP "\f(CW%Y\fR \- 4\-digit year number, e.g. 2009" 8 .IX Item "%Y - 4-digit year number, e.g. 2009" .PD 0 .ie n .IP "%y \- 2\-digit year number, e.g. 09 for year 2009" 8 .el .IP "\f(CW%y\fR \- 2\-digit year number, e.g. 09 for year 2009" 8 .IX Item "%y - 2-digit year number, e.g. 09 for year 2009" .ie n .IP "%m \- 2\-digit month, e.g. 04 for April" 8 .el .IP "\f(CW%m\fR \- 2\-digit month, e.g. 04 for April" 8 .IX Item "%m - 2-digit month, e.g. 04 for April" .ie n .IP "%d \- 2\-digit day of month, e.g. 28" 8 .el .IP "\f(CW%d\fR \- 2\-digit day of month, e.g. 28" 8 .IX Item "%d - 2-digit day of month, e.g. 28" .ie n .IP "%H \- 2\-digit hour, e.g. 01" 8 .el .IP "\f(CW%H\fR \- 2\-digit hour, e.g. 01" 8 .IX Item "%H - 2-digit hour, e.g. 01" .ie n .IP "%M \- 2\-digit minute, e.g. 57" 8 .el .IP "\f(CW%M\fR \- 2\-digit minute, e.g. 57" 8 .IX Item "%M - 2-digit minute, e.g. 57" .ie n .IP "%S \- 2\-digit second, e.g. 59" 8 .el .IP "\f(CW%S\fR \- 2\-digit second, e.g. 59" 8 .IX Item "%S - 2-digit second, e.g. 59" .ie n .IP "%z \- the time zone as hour offset from \s-1GMT\s0" 8 .el .IP "\f(CW%z\fR \- the time zone as hour offset from \s-1GMT\s0" 8 .IX Item "%z - the time zone as hour offset from GMT" .ie n .IP "%Z \- the time zone or name or abbreviation" 8 .el .IP "\f(CW%Z\fR \- the time zone or name or abbreviation" 8 .IX Item "%Z - the time zone or name or abbreviation" .IP "%{pid} \- Process \s-1ID\s0" 8 .IX Item "%{pid} - Process ID" .IP "%{ext} \- Guessed file extension" 8 .IX Item "%{ext} - Guessed file extension" .PD Try to detect appropriate file extension using File::LibMagic. For example, if log message looks like an \s-1HTML\s0 document, then 'html'. If File::LibMagic is not available or type cannot be detected, defaults to 'log'. .IP "%% \- literal '%' character" 8 .IX Item "%% - literal '%' character" .RE .RS 4 .RE .PD 0 .IP "\(bu" 4 .PD filename_sub (\e&) .Sp A more generic mechanism for \fBfilename_pattern\fR. If \fBfilename_sub\fR is given, \&\fBfilename_pattern\fR will be ignored. The code will be called with the same arguments as \fIlog_message()\fR and is expected to return a filename. Will die if code returns undef. .IP "\(bu" 4 max_size ($) .Sp Maximum total size of files, in bytes. After the size is surpassed, oldest files (based on ctime) will be deleted. Optional. Default is undefined, which means unlimited. .IP "\(bu" 4 max_files ($) .Sp Maximum number of files. After this number is surpassed, oldest files (based on ctime) will be deleted. Optional. Default is undefined, which means unlimited. .IP "\(bu" 4 max_age ($) .Sp Maximum age of files (based on ctime), in seconds. After the age is surpassed, files older than this age will be deleted. Optional. Default is undefined, which means unlimited. .IP "\(bu" 4 rotate_probability ($) .Sp A number between 0 and 1 which specifies the probability that \fIrotate()\fR will be called after each \fIlog_message()\fR. This is a balance between performance and rotate size accuracy. 1 means always rotate, 0 means never rotate. Optional. Default is 0.25. .SS "log_message(message => $)" .IX Subsection "log_message(message => $)" Sends a message to the appropriate output. Generally this shouldn't be called directly but should be called through the \f(CW\*(C`log()\*(C'\fR method (in Log::Dispatch::Output). .SH "SEE ALSO" .IX Header "SEE ALSO" Log::Dispatch .SH "HOMEPAGE" .IX Header "HOMEPAGE" Please visit the project's homepage at . .SH "SOURCE" .IX Header "SOURCE" Source repository is at . .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests on the bugtracker website .PP When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. .SH "AUTHOR" .IX Header "AUTHOR" Steven Haryanto .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2014 by Steven Haryanto. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.