NAME
Log::MultiChannel - A full featured module for implimenting log messages on multiple channels to multiple targets.
FEATURES
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.
AUTHOR
Paul LaPointe - <http://paullapointe.org>
LICENSE
This program is dual licensed under the (Perl) Artistic License 2.0, and the Lesser GNU General Public License 3.0 (LGPL).
BUGS
Please report any bugs or feature requests to bugs@paullapointe.org
JUL 31, 2014 - Changed the mapChannelToLog to be internal to avoid confusion in it's use. - Added a name to the startLoggingOnHandle fn to provide a name for these logs to work with - Added simple client-server example
METHODS
Please visit <http://paullapointe.org/MultiChannel> for complete documentation, examples, and more.
METHODS
Log ( channel, message, additional args... )
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.
startLogging( filename, preserve, limit, oldDir, printHandler )
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
startLoggingOnHandle ( name, fileHandle, printHandler )
name - Any arbitrary name for this log.
filehandle - The filehandle to log with.
printHandler - An optional special print handler for this file
stopLogging ( Log filename )
This will stop logging to the given log file.
closeLogs();
This will stop logging to ALL files (including any custom filehandles).
mapChannel ( Channel, Log filename1, Log filename2, ... )
This will map a channel to one or more log files by their name.
mapChannelToLog ( Channel, Log filename )
Maps a channel to this specific log name.
unmapChannel ( Channel )
Unmaps all logs from a channel.
enableChannel ( Channel )
Enables log messages from a specific channel.
disableChannel ( Channel )
Disables log messages from a specific channel.
enableChannelForModule ( Channel, Module )
Enables log messages from a specific module for the given channel.
disableChannelForModule ( Channel, Module )
Disabled log messages from a specific module for the given channel (overriden by channel control).
assignColorCode ( Channel , Ascii color code )
Assigns a (typically) ASCII color code to a specific channel
enableColor ( Channel )
Enables color on a specific channel.
disableColor ( Channel )
Disables color on a specific channel.
logStats ()
Returns a list with a count of all messages logged to each channel.
EXAMPLES
Example 1: The simplest use case:
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;
Example 2: Using multiple logs and channels:
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;