Pitonyak::SmallLogger - File and/or screen logging with message types
use Pitonyak::SmallLogger;
my $log = new Pitonyak::SmallLogger(); # Do not use any time/date in the file name $log->log_name_date(''); # send debug output to the screen $log->screen_output('D', 1); $log->debug(``Debug 1''); $log->warn(``Hello I Warn you''); $log->debug(``Hello I debug you''); $log->info(``Hello I info you''); $log->error(``Hello I error you'');
new()
new()
is valid!
copy($small_logger_object)
$obj1-
copy($obj2)> is the same as $obj1 = $obj2
.
The file handle is not copied and the
the receiving SmallLogger is closed first.
The complete log file name will be named as
"$path$base_file_name$time_format$extension"
with some caveats.
The $time_format
is converted to a time date string and is used
as part of the file name if it does not have a zero length.
A popular format for this is '.YYYYMMDD.hhmmss' to have a log file
that contains the date and time included as part of the file name.
This is a good way to have a unique log file every time you run
and yet still know the application to which it is attached.
This should contain a leading '.' if one is desired.
The $path
indicates where the log file will exist.
The $extension
should contain a leading '.' if one is desired.
If the file is open, it will be closed before the name is changed.
close_log()
debug($message)
write_log_type('D', $message);
returns 1 if successful, 0 otherwise
error($message)
write_log_type('E', $message);
returns 1 if successful, 0 otherwise
When a message is written, a message type is included. I use one character to indicate the message type. The screen output hash is then checked to see if that message type should be logged. This is similar to how log4j does things.
file_output()
file_output(HASH)
file_output($message_type)
$message_type
.
$o->file_output('E')
is the same as
$o->file_output()->{'E'}
.
$message_type
.
$o->file_output('E', 1)
is the same as
$o->file_output()->{'E'} = 1
.
Remember that the call $obj->method(@parms)
is the same as
method($obj, @parms)
.
get_class_attribute($attribute_name)
SmallLogger
object and the second parameter is
assumed to be an attribute name.
The attribute value for the object is returned.
hold_log_open([0|1])
write_log()
will only close
the log if it opened the log, so you can
clear hold_log_open and then manually open the
the log before a lot of writing and then
manually close the log.
No value is required, in which case, only the status is returned and the value is not changed.
If hold_log_open is set to true, you probably want open_append set to true as well.
See open_append()
for more details.
info($message)
write_log_type('I', $message);
returns 1 if successful, 0 otherwise
is_log_open()
Do not attempt to set this directly, use the open_log()
or close_log()
methods instead.
is_ok([0|1])
Although you may set this, there is no real reason to do so. This will be set if there is a problem opening the file, for example.
log_ext([$log_extension])
If the log is currently open, it will be closed when the name changes.
log_name()
log_name_date([$new_date_format])
log_path([$new_log_path])
If the log is currently open, it will be closed when the name changes.
log_primary_name([$new_primary_name])
If the logfile is currently open, then the
file is closed before changing the name.
The default value is the base name of $0 with
the extension removed. This is what is used
if set_log_primary_name()
is used.
No value is required, in which case, only the primary name is returned and the value is not changed.
message_front([$front_string])
A message is printed as
$mesage_type message_front() message_time_format() message_loc_format()
message_loc_format([$location_format])
This determines the format of the location
information, if any, that is printed to the
log file. The text with fields replaced will
be used.
The default value for the location format is '(file):(sub):(line)'
.
The (package) token is not used because the sub
name contains the package.
A message is printed as
$mesage_type message_front() message_time_format() message_loc_format()
message_time_format([$time_format])
When a line is printed, it contains the message type,
message_front()
formatted time/date stamp as stored by message_time_format(),
this location format string, and then finally the message.
A message is printed as
$mesage_type message_front() message_time_format() message_loc_format()
open_append([0|1])
Returns the current value of the attribute.
open_log()
read_from_file($file_name)
rebuild_name()
build_name()
with appropriate parameters.
This value is then returned.
When a message is written, a message type is included. I use one character to indicate the message type. The screen output hash is then checked to see if that message type should be logged. This is similar to how log4j does things. See file_output().
screen_output()
screen_output(HASH)
screen_output($message_type)
$message_type
.
$o->screen_output('E')
is the same as
$o->screen_output()->{'E'}
.
$message_type
.
$o->screen_output('E', 1)
is the same as
$o->screen_output()->{'E'} = 1
.
set_log_primary_name([$new_primary_name])
log_primary_name()
method
is then used to set the primary name.
trace($message)
write_log_type('T', $message);
returns 1 if successful, 0 otherwise
warn($message)
write_log_type('W', $message);
returns 1 if successful, 0 otherwise
returns 1 if successful, 0 otherwise
$message_type
is usually a single character such as
'D', 'E', 'W', 'T', 'I' etc. representing things such as
debug, error, warning, trace, info, etc.
The $message_type
determines if the message should be printed to the file and/or screen.
The $message_type
is always printed as the first thing on the line.
returns 1 if successful, 0 otherwise
$message
to the screen if $to_screen
evaluates to true.
This writes the $message
to the file if $to_file
evaluates to true.
returns 1 if successful, 0 otherwise
This will open the file if it must.
This will never close the file unless it
opened the file and hold_log_open()
is false.
write_to_file([$file_name])
Copyright 1998-2002, Andrew Pitonyak (perlboy@pitonyak.org)
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Version 1.00 First release
Version 1.01 Changed internal documentation to POD