This page explains the Logger adapter in Bridge context. If you were looking for the same information regarding the PAS Designer, refer to Logger Adapter in the Designer guide. |
Runtime 2020.8 If you have special logging needs, you do not need to stick with the standard logging configuration (xUML Service Standard Log and xUML Service Transaction Log): You can define your own logger configuration based on the concepts of channels and sinks:
For more information about the concept in general, refer to xUML Runtime Logger Configuration.
In your UML, models, you can define your own custom channel and sinks to log to.This is done by class diagram containing a set of classes with dedicated stereotypes:
Define the corresponding classes and relate them with containment relations as depicted below:
The above class diagram defines the following configuration:
Channel | Sink | Log Format | ||
---|---|---|---|---|
Channel_Custom | Sink_1 | Filename / Path |
| 2020-06-25-16 This is an example log message |
Content | Log all messages with log level Info or higher to this sink. | |||
Type | Rotate log file hourly. | |||
Format | Output logs to a text file using a dedicated pattern. | |||
Sink_2 | Filename / Path |
| {"time":"at 10:22:03","channel":"Channel_Custom","description":"This is an example warning"} | |
Content | Log all messages with log level Warning or higher to this sink. | |||
Type | Rotate log file hourly. | |||
Format | Output logs in JSON format. | |||
JSON attributes |
|
For a detailed description of all tagged values and their allowed values refer to logger.
Sinks can be configured to log to a file by using a sinkType that is daily_rotated_file or hourly_rotated_file. In these cases, you can specify a filename pattern for the log file to be generated using a <<LogFormatter>> class.
The following variables are available:
Refer to Log Adapter Reference for more formatting options.
You can only define one <<LogFormatter>> per sink. |
As per default, the Logger logs to a JSON file if a custom configuration is specified. You have several options to change the log file content, though.
Sinks can be configured to log to a text file by setting format of the related <<LogFormatter>> class to pattern.
To format the content of text files, you can use the following variables in tagged value pattern:
Refer to Log Adapter Reference for more formatting options.
Sinks can be configured to log to a JSON file by setting format of the related <<LogFormatter>> class to json.
For JSON log files, the following JSON attributes are available:
If nothing is specified but format = json, the default configuration will be used and the log file will look like
{"at":"<a timestamp>","message":"<a log message>"} |
You can change the appearance of the JSON file using a <<LogKeys>> class to specify your changes.
This is done by adding an attribute to the <<LogKeys>> class whose name corresponds to the name of the attribute you want to change.
Then, set the tagged values as follows:
Topic | Tagged Value | Allowed Values | ||
---|---|---|---|---|
add attribute | externalName | You can add all attributes listed in the table above. Attributes are only visible if an external name has been added. The external name, however, may be the same name as the name of the attribute. | ||
remove attribute | Empty all tagged values. | |||
change attribute name | externalName | Specify a name for the JSON attribute to be used in the log file. This name must conform to the rules for JSON attribute names. | ||
change type of attribute "at" | externalType | integer | Convert to Integer. | |
string | Convert to String. | |||
change format of attribute "at" | formatString | Specify how to format the content when serializing it to the specified externalType. Refer to Log Adapter Reference for all available formatting options.
|
In the component diagram of the xUML service, draw a dependency from the composite to the log channels you want to use:
With the <<Logger>> adapter you can write into the log file of the service. Use action logTo in this case to use your custom logger configuration.
The following picture shows the usage of the <<Logger>> adapter:
Tag action of the logger adapter needs to be set to logTo. Additionally, provide the channel you want to log to.
The following input can be provided:
As an alternative - e.g. to set the channel dynamically - you can use Action Script and the logTo.
Pin | Value |
---|---|
channel |
|
level |
|
message |
|
The output after running the example can be found in custom logfile logs/logfile_Channel_Custom.Sink_1_2020-06-25-16:35:46.log
.
2020-06-25 Synchronized.
Pin | Value |
---|---|
channel |
|
level |
|
message |
|
The output after running the example can be found in both logfiles:
logs/logfile_Channel_Custom.Sink_1_2020-06-25-16.log
2020-06-25 Item not available.
logs/logfile_Channel_Custom.Sink_2_2020-06-25-16.log
{"time":"at 10:22:03","channel":"Channel_Custom","description":"Item not available."}