Since version 3.8.0, version 2 of the function-API is available. It includes a number of logging methods that can be used to log errors and debugging information.
Set the file name of the log file (setLogFilename(Param1[ Param2, Param3]))
Sets the file name of the log file (overwrites the default value).
Parameter |
Type |
Description |
|---|---|---|
$fileName |
string |
File name of the log file Default value: processName_version_YYYYMMDD.log |
$format |
string |
Format specifications for the name of the log file (optional)
Default value: {filename}_{date} |
$dateFormat |
string |
Format specifications for the date in the name of the log file (optional)
Default value: Ymd
Possible values: •Y-m-d •Y_m_d •Y.m.d |
Please note: If no date is passed in the format specification, the current date will be added automatically to the end of the log file name.
Examples:
...
$logName = $this->getConfiguration('log_name'); // Retrieve the name for the log file from a process configuration
$this->setLogFilename($logName);
...
$logName = $this->setLogFilename('InvoiceNumbers.log', '{date}_{filename}', 'Y-m-d'); // 2021-09-21_InvoiceNumbers.log
Setting the directory path of the log file (setLogFilePath)
Sets the directory path of the log file (overwrites the default value).
Parameter |
Type |
Description |
|---|---|---|
$filePath |
string |
Directory path of the log file Default value: JobRouter directory output/log output/log |
Example:
...
$logPath = $this->getConfiguration('log_path'); // Reading the directory path of the log file from the process configuration
$this->setLogFilePath($logPath);
...
Setting the name of the log channel (setLogChannel)
Sets the name of the log channel (overwrites the default value). The log channel is written as prefix of the log entry in the log file.
Parameter |
Type |
Description |
|---|---|---|
$channel |
string |
Name of the log channel Default value: incidentNumber.stepNumber.functionClassName |
Example:
...
$logChannel = $this->getTableValue('INVOICENUMBER'); // Reading the invoice number from the process table
$this->setLogChannel($logChannel);
...
Setting the log level (setLogLevel)
Sets the minimum degree of severity of the entries that are to be logged, the so called log level (overwrites the default value). Only entries with a severity of the same height or higher than the currently set log level are written into the log file.
By default, the value of the constant CONST_LOG_LEVEL_FILE from the config.php file is used as log level. CONST_LOG_LEVEL_FILE aus der verwendet. If this constant is not defined, the value WARNING is used. verwendet.
To ensure that the log entries of your PHP function are logged independently of the global settings, call this function at the beginning of the execute method of your PHP function with the appropriate value for the $level parameter. execute mit dem entsprechenden Wert für den Parameter in der PHP-Funktion auf.
Parameter |
Type |
Description |
|---|---|---|
$level |
string |
Minimum severity of the to be logged entries
Possible values for the severity: DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY Default value: Value of the CONST_LOG_LEVEL_FILE from the config.php CONST_LOG_LEVEL_FILE aus |
Example:
...
$logLevel = $this->getConfiguration('log_level'); // Reading the log level from the process configuration
$this->setLogLevel($logLevel);
...
Sets the output format of log entries (setLogMessageFormat)
Sets the output format for log entries (overwrites the default value).
Parameter |
Type |
Description |
|---|---|---|
$format |
string |
Output format for log entries Default value: %datetime% %channel%.%level_name%: %message% %context% %extra% The following variables can be used when specifying the output format: •%datetime% •%channel% •%level_name% •%message% •%context% •%extra% |
Example:
...
$this->setLogMessageFormat('%datetime% [%level_name%] %message% %context%');
...
Deactivating the output formatting of log entries (rawLog)
Deactivates the formatting of log entries entirely. Log entries will be written into the log file unchanged.
Parameter |
Type |
Description |
|---|---|---|
- |
- |
- |
Example:
...
$this->rawLog();
$invoicedata = ['invoicenumber' => 43523453, 'invoicedate' => '2015-07-01', 'customernumber' => '5325438'];
$this->debug($invoicedata);
...
Output of any object into the log file (dump)
Writes the passed object as PHP-parse-able character string into the log file.
Parameter |
Type |
Description |
|---|---|---|
$var |
mixed |
Any object, array or scalar value |
Example:
...
$invoicedata = ['invoicenumber' => 43523453, 'invoicedate' => '2015-07-01', 'customernumber' => '5325438'];
$this->dump($invoicedata);
...
Output of log entries with stated severity (log)
Writes an entry with the stated severity into the log file
Parameter |
Type |
Description |
|---|---|---|
$level |
string |
Severity of the to be logged entry
Possible values for the severity: DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY |
$message |
string |
Text of the log entry |
$context |
array |
Context data (optional) |
Example:
...
$invoicenumber = $this->getTableValue('INVOICENUMBER'); // Reading the invoice number from the process tableRECHNUNGSNUMMER'); // Rechnungsnummer aus Prozesstabelle lesen
$this->log('INFO', 'Matching data.', ['invoicenumber' => $invoicenumber]);
...
Output of log entries with a specific severity
Each level of severity has a separate method used to write the respective entries into the log file. The name of the method corresponds to the severity (That is: emergency, alert, critical, error, warning, notice, info, debug). emergency alert critical error warning info debug
Parameter |
Type |
Description |
|---|---|---|
$message |
string |
Text of the log entry |
$context |
array |
Context data (optional) |
Example:
try {
// Program code causing the JobRouterException
} catch (JobRouterException $e) {
$this->error($e->getMessage());$e->getMessage());
throw new JobRouterException('An error occurred. Further details can be found in the log file.');
}