In LoxBerry, you can use the integrated logging feature, currently available for Perl an Bash.
It enables a really easy way to create logfiles in Bash and Perl (and later PHP) and the logging features are geared to each other:
- The initialization and logging commands are equal (or, as equal as possible in every language)
- All logging features, in every language, create the same output format
- All the logs from each language can be viewed in the integrated log viewer
- The logfiles can be handed over from script to script, and even from language to language.
LoxBerry Log does not need to create logfiles. You can use LogBerry Log to print message to the default error log (syslog of Linux or cgierr log of Lighty).
The loglevel setting is integrated in LoxBerry. Your script logs entries in the desired loglevels, and LoxBerry will filter by the loglevel set by the user in the Plugin Management widget. Therefore, you don't need to create a logging switch or loglevel setting in your plugin.
Start easy logging
Initialize the log
Start the log by executing STARTLOG.
You have to set the PACKAGE to the folder name of your plugin. To get your folder name, use on of there options: Wie findet man das eigene Installationsverzeichnis heraus? (LoxBerry V1.x)
It is important to send the pluginfolder name with the
As you can see, no special loglevel was set. Using your plugin name from
PACKAGE, the logging feature queries the plugin database for the loglevel set by the user.
APPEND=1 if you do not want to overwrite an existing logfile.
The following logging functions will filter your messages by the loglevel set by the user.
Now you can log with the loglevel function corresponding to the severity of your log entry:
For normal logging, use
LOGERR. For debugging use
LOGCRIT if your script has to terminate early because of an unrecoverable error. In this case, logging automatically switches to loglevel 6 ("Auto-Raise"), and you can add further log messages with e.g. LOGINF that appear in the logfile.
Currently do not use the severities 0 and 1 (
LOGEMERGE) because they may be used for email alerting in future versions.
Finish the log
For ending the log note LOGEND
Appending other output to the logfile
Simply pipe the output to the file:
This output does not get any severity level tags and automatically is detected as
LOGINF from the log viewer.
Logfile and STDERR
In some situations you want logging appear on the screen and in the logfile.
Using the variable
STDERR=1 before the
LOGSTART event to write the log and show the messages:
Messages are automatically sent to STDERR instead (and would therefore appear on the screen).
No logfile, only STDOUT
In some situations you don't need a logfile, but only want your log messages sent to STDOUT.
Using the variable NOFILE=1 before the LOGSTART event, you can disable your logfile at all:
Messages are automatically sent to STDOUT instead.
If you set STDERR=1, the messages will additionally be sent to STDERR.
Automatically create a new logfile everytime
Used as plugin log, you can simply set the PACKAGE and NAME and LoxBerry Logging will always create a new logfile with a timestamp in your plugin log directory.
After the LOGSTART event, the current filename is set in the
FILENAME variable, to use it for piping other output.
If you want to have more than one log, no problem. You have to simply set your new variables an start the other log by executing LOGSTART. To select the log you have to set the variabel ACTIVELOG. every LOGSTART increases the number by 1. Use ACTIVELOG=2 for the second log.
See the description of the log levels here: Perl-Modul LoxBerry::Log
All parameters you can set
For starting the log you can set variables to change the behavoiur of logging. This is the full table of settings. Some settings are mutually exclusive and cannot be set together with other settings.
|PACKAGE||-||Mandatory||The name of the package is your plugin folders name (e.g. "|
|NAME||-||Mandatory||The name of the specific log. You can have multiple logs in your plugin, that use different names.|
|FILENAME||-||Optional/Recommended||The complete path of your logfile. If you want a fixed logfile name, set the |
|LOGDIR||-||Optional||If no |
|APPEND=1||0||Optional/Recommended||Append the log to an existing logfile. Used together with |
|NOFILE=1||0||Optional||No logfile will be created, the output goes to STDOUT. This is useful if you don't need a logfile at all. Everything is written to the console.|
|STDERR=1||0||Optional||Send the output (also) to STDERR.|
|ADDTIME=1||0||Optional||Add timestamp to your log entries. Usualley, only the start and end time are collected in the log. With |
You DO NOT NEED to set a loglevel, as the loglevel is read from the user setting in the plugin management.
You shouldn't set this, but you can override the loglevel set by the user.