Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space WBRIDGE and version 22.1.1
Hint_designer
PageDESIGNER:Logger Adapter
TopicLogger adapter

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:

Multiexcerpt include
MultiExcerptNamedefinition_channel_sink
PageWithExcerptxUML Runtime Logger Configuration

For more information about the concept in general, refer to xUML Runtime Logger Configuration.

Modeling a Custom Logger Configuration

Multiexcerpt include
SpaceWithExcerptINTERNAL
MultiExcerptNamelogto
nopaneltrue
PageWithExcerptINTERNAL:_examples_BRIDGE

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:

  • <<LogChannel>> for channels
  • <<LogSink>> for sinks
  • <<LogFormatter>> for logfile content formats
  • <<LogKeys>> for defining your own JSON format on base of the standard JSON

Define the corresponding classes and relate them with containment relations as depicted below:

The above class diagram defines the following configuration:

ChannelSinkLog Format
Channel_Custom



Sink_1Filename / Path

logs/logfile_Channel_Custom.Sink_1_2020-06-25-16.log

2020-06-25-16 This is an example log message
ContentLog all messages with log level Info or higher to this sink.

Type

Rotate log file hourly.
FormatOutput logs to a text file using a dedicated pattern.
Sink_2


Filename / Path

logs/logfile_Channel_Custom.Sink_2_20200625_16.log

{"time":"at 10:22:03","channel":"Channel_Custom","description":"This is an example warning"}
ContentLog all messages with log level Warning or higher to this sink.
TypeRotate log file hourly.
FormatOutput logs in JSON format.
JSON attributes
  • Add channel to the logged content
  • Overwrite attribute name message with name description.

  • Change name and format of the timestamp (at).

For a detailed description of all tagged values and their allowed values refer to logger.

Defining the Filename of the Log File

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:

Multiexcerpt include
MultiExcerptNamefilename_pattern_variables
PageWithExcerptlogger

Refer to Log Adapter Reference for more formatting options.

Info
iconfalse

You can only define one <<LogFormatter>> per sink.

Defining the Format of the Logged Content

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.

Logging to Text Files

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:

Multiexcerpt include
MultiExcerptNamelog_content_text_pattern_variables
PageWithExcerptlogger

Refer to  Log Adapter Reference for more formatting options.

Logging to JSON Files

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:

Multiexcerpt include
MultiExcerptNamelog_content_json_attributes
PageWithExcerptlogger

  • If nothing is specified but format = json, the default configuration will be used and the log file will look like

    Code Block
    {"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.

    Image Modified

    Then, set the tagged values as follows:

    Channel is the only attribute that can be added to the log file

    be the same name as the name of the attribute.

    OperationTopicTagged Value

    Allowed Values

    add attribute channel
    externalName

    Add You can add all attributes listed in the table above. Attributes are only visible if an external name to make this attribute visiblehas been added. The external name, however, may also be just "channel".

    Info
    iconfalse
    remove attributeEmpty all tagged values.
    change attribute nameexternalNameSpecify 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"
    externalTypeinteger

    Convert to Integer.

    stringConvert 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.

    Info
    iconfalse

    Note, that the format string must match the specified externalType. The xUML Compiler cannot check the correctness of this format string.

  • The Compiler will show an error if you try to add an unknown attribute to the <<LogKeys>> class.

Using a Custom Logger Configuration

Components

In the component diagram of the xUML service, draw a dependency from the composite to the log channels you want to use:

Activity Diagram

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:

Multiexcerpt include
MultiExcerptNameparameters_logTo
PageWithExcerptlogger

As an alternative - e.g. to set the channel dynamically - you can use Action Script and the logTo.

Example

Info (Sink_1)

PinValue
channel

Channel_Custom

level

Info

message

Synchronized.

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.

Warning (Sink_1 and Sink_2)

PinValue
channel

Channel_Custom

level

Warning

message

Item not available.

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."}