Metainformationen zur Seite

LoxBerry::Log::get_logs

@logs = LoxBerry::Log::get_logs([$package], [$name]);

Returns the current available logfiles, optional filtered by $package or $package and $name. Returns an array with a hashref to each logfile.

The $package is the owner of the logfiles. To get the logfiles of your plugin, use the $lbpplugindir variable.

Inside the package, you can filter by the name using the  $name parameter. This must be equal (case-sensitive) to the $name you have specified on creating your logfile with LoxBerry::Log::new.

get_logs always checks if the file is still available. If the logfile isn't found, it does not return it in the array.

Parameter

ParameterRequiredBeschreibung
$package This is, where the logfiles belong to. In a plugin, always use the variable $lbpplugindir.\\Omiting the $package and $name parameter will return all logfiles (including system logfiles).
$name Filters by the logfile group name, the logfiles belongs to.
Case sensitivity

The content of $package and $name is case-sensitive. If you set the name => "Daemon", you have to query "Daemon".

Return value

The function returns an array with all found logfiles. Every array element contains a hash with one logfile. The labels are case-sensitive, therefore you have to read e.g. the $log->{NAME} (not $log→{name}).

Each notification also contains all attributes that where stored by LoxBerry::Log. 

Key Value
PACKAGE The log package the logfile belongs to.
NAME The log name the logfile belongs to.
FILENAME The filename of the file.
STATUS This is a number from 0 to 7, representing the highest severity level in the logging session occured.
This is collected during a logging session, not from the content of the logfile (in the case you append the log).
LOGSTARTMESSAGE The message that the author provided with the LOGSTART event. The string can be empty.
LOGENDMESSAGE The message that the author provided with the LOGEND event. The string can be empty.
LOGSTARTSTR These keys return the time the logfile was started, ended and the last update time of the database, all in an human-readable time format (DD.MM.YYYY hh:mm:ss).

LOGENDSTR may be empty, if the log is still in use, the logging process has terminated unexpected, or the developer has forgotten to finish the log with an LOGEND call.
LOGENDSTR
LASTMODIFIEDSTR
LOGSTARTISO These keys return the time the logfile was started, ended and the last update time of the database, all in ISO 8601 format (yyyy-mm-ddThh:mm:ssZ)

LOGENDISO may be empty, if the log is still in use, the logging process has terminated unexpected, or the developer has forgotten to finish the log with an LOGEND call.
LOGENDISO
LASTMODIFIEDISO
LOGSTARTBYTE This number is the starting position of this log session in bytes in the logfile. This is thought to be used to jump to the position with the logviewer. AVAILABLE FROM V1.2.5

There are circumstances where the position can be outdated, e.g. when logrotate has cleared logfiles or LoxBerry rebooted, and therefore a new file was started.
KEY This is the unique logfile key.
_ISPLUGIN This property is 1 if the logfile was created by a plugin.
PLUGINTITLE This property represents the full plugin title of the plugin that created the logfile.
ATTENTIONMESSAGES(From V1.2.5) Includes a \n separated list of all events with severity warning and higher, in the order of appearance.

The messages are prefixed with the severity in the logfile style, e.g. <WARNING> message\n<WARNING> anothermessage

Usage

use LoxBerry::Log;
 
# Filtered to a specific plugin and the log name (group) "Daemon".
my @logs = get_logs( $lbpplugindir, "Daemon");
 
for my $log (@logs ) {
 print "Logfile of package $log->{PACKAGE} and group $log->{NAME} is saved at $log->{FILENAME} at $log->{LOGSTARTSTR}.";
}
 
# Check if a specific attribute is present:
for my $log (@logs ) {
    next if (! $log->{LOGENDSTR} );
 
    # All logfiles without end have been skipped.
    # do stuff with the other logfiles.
}
 
# Access properties of the first logfile of the array
print $logs[0]->{LOGSTARTSTR};
 
# Get the filename of the last (newest) logfile and the status
foreach my $log ( sort { $b->{LOGSTARTISO} cmp $a->{LOGSTARTISO} } @logs ) { # grab the newest one
    $logfile = $log->{FILENAME};
    $logstatus = $log->{STATUS};
    last;
}