LogLite(3pm)
π NAME π
okay so bestie, listen: Log::LogLite is the class that helps us create simple logs for our application. that's the whole assignment and it ate. β¨
(this is the LogLite(3pm) page, living its best life over in the User Contributed Perl Documentation section, fyi π«Ά)
β¨ SYNOPSIS β¨
use Log::LogLite;
my $LOG_DIRECTORY = "/where/ever/our/log/file/should/be";
my $ERROR_LOG_LEVEL = 6;
# create new Log::LogLite object
my $log = new Log::LogLite($LOG_DIRECTORY."/error.log", $ERROR_LOG_LEVEL);
...
# we had an error
$log->write("Could not open the file ".$file_name.": $!", 4);
πΈ DESCRIPTION πΈ
so the vibe is: to have a log, you first gotta make a Log::LogLite object. that object gets created with a logging level, and the default logging level is 5, no cap.
once your Log::LogLite object exists, every call to the write method may drop a new line into the log file. the rule? if the level of the message is lower or equal to the logging level, the message gets written to the log file. otherwise it's giving silent treatment, respectfully.
the format of the logging messages can be controlled by changing the template, and by defining a default message. and plot twist β the class uses the IO::LockedFile class. π
π CONSTRUCTOR π
new ( FILEPATH [,LEVEL [,DEFAULT_MESSAGE ]] )
the constructor, the main character. β¨
FILEPATHis the path of the log file.LEVELis the defined logging level β aka theLEVELdata member.DEFAULT_MESSAGEwill define theDEFAULT_MESSAGEdata member β a message that gets added to the message of each entry in the log (according to theTEMPLATEdata member, see below).
the levels can be literally any levels that the user chooses to use. there are, though, recommended levels:
0 the application is unusable
1 the application is going to be unusable
2 critical conditions
3 error conditions
4 warning conditions
5 normal but significant condition
6 informational
7+ debug-level messages
the default value of LEVEL is 5. the default value of DEFAULT_MESSAGE is "" (empty string, iconically quiet). returns the new object. π«Ά
π METHODS π
write( MESSAGE [, LEVEL ] )
if LEVEL is less or equal to the LEVEL data member, or if LEVEL is undefined, the string in MESSAGE will be written to the log file. does not return anything. it just does the thing and leaves. main character energy honestly. π
level( [ LEVEL ] )
access method to the LEVEL data member. if LEVEL is defined, the LEVEL data member will get its value. returns the value of the LEVEL data member. π
default_message( [ MESSAGE ] )
access method to the DEFAULT_MESSAGE data member. if MESSAGE is defined, the DEFAULT_MESSAGE data member will get its value. returns the value of the DEFAULT_MESSAGE data member. π
log_line_numbers( [ BOOLEAN ] )
if this flag is set to true, the <called_by> string will hold the file that calls the subroutine and the line where the call is issued. the default value is zero. (so by default, no receipts. π)
template( [ TEMPLATE ] )
access method to the TEMPLATE data member. the TEMPLATE data member is a string that defines how the log entries will look like. the default TEMPLATE is:
'[<date>] <<level>> <called_by><default_message><message>'
where:
<date>will be replaced by a string that represent the date. for example:09/01/2000 17:00:13<level>will be replaced by the level of the entry.<called_by>will be replaced by a call trace string. for example:CGIDaemon::listen > MyCGIDaemon::accepted<default_message>will be replaced by the value of theDEFAULT_MESSAGEdata member.<message>will be replaced by the message string that is sent to theC<write>method.
returns the value of the TEMPLATE data member. β¨
π AUTHOR π
Rani Pinchuk, rani@cpan.org β the icon, the legend, the whole blueprint. π
π¦ COPYRIGHT π¦
Copyright (c) 2001-2002 Ockham Technology N.V. & Rani Pinchuk. All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself. (legal besties, we love to see it π«Ά)
π SEE ALSO π
and that's the whole page, bestie β brought to you by perl v5.36.0, dated 2022-12-04. slay, bye π β¨
π¦ where this page comes from
- debian bookworm: liblog-loglite-perl 0.82-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: liblog-loglite-perl 0.82-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: liblog-loglite-perl 0.82-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: liblog-loglite-perl 0.82-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liblog-loglite-perl 0.82-9 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms