Log::MultiChannel - A full featured module for implementing log messages on multiple channels to multiple targets.
Features: - Multi-channel logging, with the ablity to enable or disable channels dynamically.
- Channels can be mapped to multiple Log files for duplication of messages.
- Channels can be optional color coded. Each log file can enable or disable the color feature.
- Channels can be selectively enabled for messages from specific modules.
Advanced features:
- Channels can be mapped to your own handles (Eg. socket) for writting to things beside log files.
- Each Log file can use its own print function, or default to the one provided.
Features for limiting and cycling logs:
- Log files can optionally be limited to a specific line count.
- Old copies of log files can optional be perserved or overwritten.
- Old log files can be optionally moved to a different directory.
Coming soon:
- Thread safety.
Paul LaPointe - <http://paullapointe.org>
This program is dual licensed under the (Perl) Artistic License 2.0, and the Lesser GNU General Public License 3.0 (LGPL).
Please report any bugs or feature requests to bugs@paullapointe.org
Please visit <http://paullapointe.org/MultiChannel> for complete documentation, examples, and more.
Channel can be any string. Message is the log message to write. Additional args can be passed in for use by a custom log handler.
filename - the fully qualified filename for the log.
preserve - An option to retain old copies of the log before overwritting (0 or 1).
limit - An optional limit on the number of lines that can be written before cycling this log.
oldDir - Move old log files to this fully qualified directory when overwritting.
printHandler - An optional special print handler for this file. Three print handlers are included in the module itself: - logPrint - This is includes the date (only when it changes), time, channel, source filename, source line. E.g: ---- 2014 Oct 8 ---- 17.50.49 INF t/smokeTest.t-25 This is a test.
- logPrintVerbose - This is includes the date and time, channel, source filename, source line. E.g: INF Wed Oct 8 23:42:25 2014 t/smokeTest.t-101 This is the logPrintVerbose handler. - logPrintSimple - E.g: INF This is the logPrintSimple handler.
name - Any arbitrary name for this log.
filehandle - The filehandle to log with.
printHandler - An optional special print handler for this file
This will stop logging to the given log file.
This will stop logging to ALL files (including any custom filehandles).
This will map a channel to one or more log files by their name.
Maps a channel to this specific log name.
Unmaps all logs from a channel, or from a specific log file.
Enables log messages from a specific channel.
Disables log messages from a specific channel.
Enables log messages from a specific module for the given channel.
Disabled log messages from a specific module for the given channel (overriden by channel control).
Assigns a (typically) ASCII color code to a specific channel
Enables color on a specific log filename.
Disables color on a specific log filename.
Returns a list with a count of all messages logged to each channel.
use Log::MultiChannel qw(Log); Log::MultiChannel::startLogging('myLogFile.log'); Log('INF','This is an info message'); # This will default to the last log openned ... Log::MultiChannel::stopLogging('myLogFile.log'); exit;
use Log::MultiChannel qw(Log); Log::MultiChannel::startLogging('myLogFile1.log'); Log::MultiChannel::startLogging('myLogFile2.log'); Log::MultiChannel::mapChannel('INF','myLogFile1.log'); # Put INF messages in myLogFile1.log Log::MultiChannel::mapChannel('ERR','myLogFile2.log'); # Put ERR messages in myLogFile2.log Log('INF','This is an Error message for myLogFile1.log'); Log('ERR','This is an info message for myLogFile2.log'); Log::MultiChannel::closeLogs(); # This will close ALL log files that are open exit;
#!/usr/bin/perl # Example 8: This will tee (copy) the output that is sent to a log file # to STDOUT, so it can be seen as the program runs. use strict; use warnings; use Log::MultiChannel qw(Log); Log::MultiChannel::startLogging('myLogFile1.log'); Log::MultiChannel::startLoggingOnHandle('STDOUT',\*STDOUT); Log::MultiChannel::mapChannel('INF','myLogFile1.log','STDOUT'); # Put INF messages in myLogFile1.log Log('INF','This is an Error message for myLogFile1.log, that will also be printed on STDOUT'); Log::MultiChannel::closeLogs(); # This will close ALL log files that are open exit;
To install Log::MultiChannel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::MultiChannel
CPAN shell
perl -MCPAN -e shell install Log::MultiChannel
For more information on module installation, please visit the detailed CPAN module installation guide.