Skip to main content

Logging With Processes

Overview

In this lesson you will learn how to add logging to an application process.

[ * Time to Complete: 30 minutes ]

What You Will Learn

  1. The types of actions available that can be used for logging
  2. When each type of action should be used

Pre-requisites

Before starting this lesson, you should already be familiar with

  1. How to attach logging configuration to an application
  2. How to create a simple application process
  3. How to find actions and control their inputs
  4. Controlling the flow of an application process
    1. Loops and conditionals
    2. Sleeps and waits
    3. Using events and outcomes to handle exceptions

Instructions

Enabling Process Logging

In the log properties file the following properties will enable process logging

  • com.enactor.coreUI.actions.level=LOG_DEBUG
  • com.enactor.coreUI.states.level=LOG_DEBUG
  • com.enactor.coreUI.processes.level=LOG_DEBUG

Logging for individual processes follows the same format as classes. For processes you use their process id. To be able to determine if logging is for a class or a process, processes need to be given a prefix of Process. For example to log the process Example/Path/ProcessId you would include the following entry in your log configuration.

  • Process.Example.Path.ProcessId.level=LOG_DEBUG

Simple Logging

To produce a simple log message using UILogMessageAction

Task - You will be creating a process that will do the following with UILogMessageAction

  1. Log messages as it progresses
  2. Catch an exception

The following input data will be used

  • Exception

    • Type: Exception
    • An exception that has been caught during the application flow
    • This will always be the most recent exception unless explicitly mapped
    • The most recent exceptions does not need to be explicitly mapped to be provided
  • enactor.coreUI.LogMessage

    • Type: String
    • Supply a custom message for the log
    • This message will always be at the start if other data is also being logged
  • enactor.coreUI.logging.LogLevel

    • Type: String
    • Set the enactor level to use for this log
    • If an exception is available the log will always use ERROR
  • enactor.coreUI.Object

    • Type: Object
    • Include an object to provide additional context with the log
    • If not already a string, the action will determine how best to convert the object to a string
  1. Create a new application process called DoSomeLogging
    1. It should have an initial state called Start
    2. It should have the following process outcomes
      1. Success
      2. Fail
  2. Add a UILogMessageAction called LogProcessStart
    1. Link the StateEntered event from the Start state to the action LogProcessStart
    2. Define the LogMessage to be 'The process has started'
    3. Define the LogLevel to be LOG_DEBUG
  3. Add a UILogMessageAction called LogProcessEndSuccess
    1. Link the action LogProcessEndSuccess to the End Process Action for outcome Success
    2. Define the LogMessage to be 'The process is ending successfully'
    3. Define the LogLevel to be LOG_DEBUG
  4. Add actions to load an entity
    1. Use the User entity
    2. Link the load entity action to LogProcessEndSuccess
  5. Update LogProcessEndSuccess to log the loaded entity
    1. Map the loaded entity into the Object data for LogProcessEndSuccess
  6. Add a UILogMessageAction called LogEntityLoad
    1. Link action LogProcessStart to LogEntityLoad
    2. Link action LogEntityLoad to the actions to create the user key
    3. Define the LogMessage to be 'Preparing to load user'
    4. Define the LogLevel to be LOG_WARNING
  7. Add a UILogMessageAction called LogEntityException
    1. Link an Exception link from the load entity action to LogEntityException
    2. Link LogEntityException to the End Process Action for outcome Fail
    3. Define the LogMessage to be 'An exception occurred while loading the user'
    4. Define the LogLevel to be LOG_ERROR
  8. Execute the process DoSomeLogging
    1. Attach the log properties to the launch
    2. Run the application with process logging enabled
    3. Repeat this by changing the logging level to each of the following levels
      • LOG_DEBUG
      • LOG_WARNING
      • LOG_ERROR
    4. Observe how the log files differ

Restricted Logging

The UILogMessageAction also has support for restricting individual log messages. This prevents the log file from filling with repetitive information. The restriction is based on the entire message being logged, so only short messages should be restricted. Otherwise the logging may become a bottleneck in the application performance.

Task - You will be creating a process that will do the following with UILogMessageAction

  1. Log a simple message inside a loop.
  2. Have the process sleep for a duration.
  3. Log the same message again.
  4. The above will be repeated a number of times before continuing.
  • enactor.coreUI.logging.InitialMax

    • Type: Integer
    • How many times the message can be logged before it is restricted
  • enactor.coreUI.logging.RelogDelaySecs

    • Type: Integer
    • How long the restriction will be in place
  1. Create a new application process called RepeatedLogs
    1. It should have an initial state called Start
    2. It should have the following process outcomes
      1. Success
  2. Add a Looping State called FirstLoop
    1. Link the StateEntered event from the Start state to the state FirstLoop
    2. Set the LoopCount to 10
  3. Add a UILogMessageAction called FirstLoopLog
    1. Link the Execute event from FirstLoop to the action FirstLoopLog
    2. Define the LogMessage to be 'This is a log message'
    3. Define the LogLevel to be LOG_DEBUG
    4. Define the InitialMax to be 5
    5. Define the RelogDelaySecs to be 3
  4. Add a UIWaitAction called FirstLoopDelay
    1. Link the Completed event from FirstLoop to the action FirstLoopDelay
    2. Define the WaitTimeMs to be 1200
  5. Repeat the above to create a second and third loop.
    1. Each will be executed after the delay from the previous loop
  6. Execute the process RepeatedLogs
    1. Attach the log properties to the launch
    2. Run the application with process logging enabled
    3. Do this with the level set to the following levels
      • LOG_DEBUG
    4. Observe that while UILogMessageAction is called 30 times, only 10 logs will be produced

See Also

  • Advanced Logging
  • Performance Logging
  • Audit Log
  • Service Logging
  • Print Logging
  • UI Logging
  • Entity Logging Reference
    • Promotion Logging