NAME
CTK::Log - CTK Logging
VERSION
Version 2.64
SYNOPSIS
use CTK::Log;
use CTK::Log qw/:constants/;
my $logger = CTK::Logger->new (
file => "logs/foo.log",
level => CTK::Log::LOG_INFO,
ident => "ident string",
);
$logger->log( CTK::Log::LOG_INFO, " ... Blah-Blah-Blah ... " );
$logger->log_except( "..." ); # 9 exception, aborts program!
$logger->log_fatal( "..." ); # 8 system unusable, aborts program!
$logger->log_emerg( "..." ); # 7 system is unusable
$logger->log_alert( "..." ); # 6 failure in primary system
$logger->log_crit( "..." ); # 5 failure in backup system
$logger->log_error( "..." ); # 4 non-urgent program errors, a bug
$logger->log_warning( "..." ); # 3 possible problem, not necessarily error
$logger->log_notice( "..." ); # 2 unusual conditions
$logger->log_info( "..." ); # 1 normal messages, no action required
$logger->log_debug( "..." ); # 0 debugging messages (default)
DESCRIPTION
Logger class
Log level overview:
LVL SLL NAME ALIAS NOTE
0 7 debug debugging messages, copious tracing output
1 6 info normal messages, no action required
2 5 notice note unusual conditions
3 4 warning warn possible problem, not necessarily error
4 3 error err non-urgent program errors, a bug
5 2 critical crit failure in backup system
6 1 alert failure in primary system
7 0 emergency emerg system unusable
8 0 fatal system unusable, aborts program!
9 0 exception except exception, aborts program!
* SLL -- SysLog Level
METHODS
new
my $logger = CTK::Log->new(
file => "logs/foo.log",
level => "info", # or CTK::Log::LOG_INFO
ident => "ident string",
);
Returns logger object for logging to file
my $logger = CTK::Log->new(
level => "info", # or CTK::Log::LOG_INFO
ident => "ident string",
);
Returns logger object for logging to syslog
- facility
-
The part of the system to report about, for example
Sys::Syslog::LOG_USER
. See Sys::SyslogDefault:
Sys::Syslog::LOG_USER
- file
-
Specifies log file. If not specify, then will be used syslog
Default: undef
- ident
-
Specifies ident string for each log-record
ident = "test" [Mon Apr 29 20:02:04 2019] [info] [7936] [test] Blah Blah Blah ident = undef [Mon Apr 29 20:02:04 2019] [info] [7936] Blah Blah Blah
Default: undef
- level
-
This directive specifies the minimum possible priority level. You can use:
constants:
LOG_DEBUG LOG_INFO LOG_NOTICE or LOG_NOTE LOG_WARNING or LOG_WARN LOG_ERR or LOG_ERROR LOG_CRIT LOG_ALERT LOG_EMERG or LOG_EMERGENCY LOG_FATAL LOG_EXCEPT or LOG_EXCEPTION
...or strings:
'debug' 'info' 'notice' or 'note' 'warning' or 'warn' 'error' or 'err' 'crit' 'alert' 'emerg' or 'emergency' 'fatal' 'except' or 'exception'
Default:
LOG_DEBUG
- pure
-
Specifies flag for suppressing prefixes log-data
ident = "test" pure = 0 [Mon Apr 29 19:12:55 2019] [crit] [7480] [test] Blah-Blah-Blah ident = "test" pure = 1 [test] Blah-Blah-Blah ident = undef pure = 1 Blah-Blah-Blah
Default: 0
- separator
-
Separator of log-record elements
separator = " " [Mon Apr 29 20:02:04 2019] [info] [7936] [test] Blah Blah Blah separator = "," [Mon Apr 29 20:02:04 2019],[info],[7936],[test],Blah Blah Blah
Default:
" "
- socketopts
-
Socket optrions for Sys::Syslog
Allowed formats, examples:
socketopts => "unix" socketopts => ["unix"] socketopts => { type => "tcp", port => 2486 }
Default:
native
- syslogopts
-
Options of Sys::Syslog
Default:
ndelay,pid
- usesyslog
-
Sets to 1 for send data to syslog forced
Default: 0
- utf8
-
Sets flag utf8 for logging data. The flag is enabled by default
Default: 1
error
my $error = $logger->error;
Returns error string if occurred any errors while creating the object
status
print $logger->error unless $logger->status;
Returns boolean status of object creating
LOG METHODS
log
$logger->log( <LEVEL>, <FORMAT>, <VALUE>, ... );
$logger->log( LOG_INFO, "Message: Blah-Blah-Blah" );
$logger->log( LOG_INFO, "Message: %s", "Blah-Blah-Blah" );
$logger->log( "info", "Message: Blah-Blah-Blah" );
Logging with info level (1). Same as log_info( "Message: %s", "Blah-Blah-Blah" )
log_debug
$logger->log_debug( <FORMAT>, <VALUE>, ... );
$logger->log_debug( "the function returned 3" );
$logger->log_debug( "going to call function abc" );
Level 0: debug-level messages (default)
log_info
$logger->log_info( <FORMAT>, <VALUE>, ... );
$logger->log_info( "File soandso successfully deleted." );
Level 1: informational
log_notice, log_note
$logger->log_notice( <FORMAT>, <VALUE>, ... );
$logger->log_notice( "Attempted to create config, but config already exists." );
Level 2: normal but significant condition
log_warning, log_warn
$logger->log_warning( <FORMAT>, <VALUE>, ... );
$logger->log_warning( "Couldn't delete the file." );
Level 3: warning conditions
log_error, log_err
$logger->log_error( <FORMAT>, <VALUE>, ... );
$logger->log_error( "Division by zero attempted." );
Level 4: error conditions
log_crit, log_critical
$logger->log_crit( <FORMAT>, <VALUE>, ... );
$logger->log_crit( "The battery is too hot!" );
Level 5: critical conditions
log_alert
$logger->log_alert( <FORMAT>, <VALUE>, ... );
$logger->log_alert( "The battery died!" );
Level 6: action must be taken immediately
log_emerg, log_emergency
$logger->log_emerg( <FORMAT>, <VALUE>, ... );
$logger->log_emerg( "No config found, cannot continue!" );
Level 7: system is unusable
log_fatal
$logger->log_fatal( <FORMAT>, <VALUE>, ... );
$logger->log_fatal( "No free memory" );
Level 8: fatal
log_except, log_exception
$logger->log_except( <FORMAT>, <VALUE>, ... );
$logger->log_except( "Segmentation violation" );
Level 9: exception
HISTORY
See Changes
file
DEPENDENCIES
TO DO
See TODO
file
BUGS
* none noted
SEE ALSO
AUTHOR
Serż Minus (Sergey Lepenkov) https://www.serzik.com <abalama@cpan.org>
COPYRIGHT
Copyright (C) 1998-2022 D&D Corporation. All Rights Reserved
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See LICENSE
file and https://dev.perl.org/licenses/