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
- The types of actions available that can be used for logging
- When each type of action should be used
Pre-requisites
Before starting this lesson, you should already be familiar with
- How to attach logging configuration to an application
- How to create a simple application process
- How to find actions and control their inputs
- Controlling the flow of an application process
- Loops and conditionals
- Sleeps and waits
- 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
- Log messages as it progresses
- 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
- Create a new application process called
DoSomeLogging
- It should have an initial state called
Start
- It should have the following process outcomes
- Success
- Fail
- It should have an initial state called
- Add a UILogMessageAction called
LogProcessStart
- Link the
StateEntered
event from theStart
state to the actionLogProcessStart
- Define the
LogMessage
to be 'The process has started' - Define the
LogLevel
to beLOG_DEBUG
- Link the
- Add a UILogMessageAction called
LogProcessEndSuccess
- Link the action
LogProcessEndSuccess
to the End Process Action for outcome Success - Define the
LogMessage
to be 'The process is ending successfully' - Define the
LogLevel
to beLOG_DEBUG
- Link the action
- Add actions to load an entity
- Use the User entity
- Link the load entity action to LogProcessEndSuccess
- Update LogProcessEndSuccess to log the loaded entity
- Map the loaded entity into the
Object
data for LogProcessEndSuccess
- Map the loaded entity into the
- Add a UILogMessageAction called
LogEntityLoad
- Link action LogProcessStart to LogEntityLoad
- Link action LogEntityLoad to the actions to create the user key
- Define the
LogMessage
to be 'Preparing to load user' - Define the
LogLevel
to beLOG_WARNING
- Add a UILogMessageAction called
LogEntityException
- Link an Exception link from the load entity action to LogEntityException
- Link LogEntityException to the End Process Action for outcome Fail
- Define the
LogMessage
to be 'An exception occurred while loading the user' - Define the
LogLevel
to beLOG_ERROR
- Execute the process
DoSomeLogging
- Attach the log properties to the launch
- Run the application with process logging enabled
- Repeat this by changing the logging level to each of the following levels
- LOG_DEBUG
- LOG_WARNING
- LOG_ERROR
- 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
- Log a simple message inside a loop.
- Have the process sleep for a duration.
- Log the same message again.
- 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
- Create a new application process called
RepeatedLogs
- It should have an initial state called
Start
- It should have the following process outcomes
- Success
- It should have an initial state called
- Add a Looping State called
FirstLoop
- Link the
StateEntered
event from theStart
state to the stateFirstLoop
- Set the
LoopCount
to 10
- Link the
- Add a UILogMessageAction called
FirstLoopLog
- Link the
Execute
event fromFirstLoop
to the action FirstLoopLog - Define the
LogMessage
to be 'This is a log message' - Define the
LogLevel
to beLOG_DEBUG
- Define the
InitialMax
to be 5 - Define the
RelogDelaySecs
to be 3
- Link the
- Add a UIWaitAction called
FirstLoopDelay
- Link the
Completed
event from FirstLoop to the action FirstLoopDelay - Define the
WaitTimeMs
to be 1200
- Link the
- Repeat the above to create a second and third loop.
- Each will be executed after the delay from the previous loop
- Execute the process
RepeatedLogs
- Attach the log properties to the launch
- Run the application with process logging enabled
- Do this with the level set to the following levels
- LOG_DEBUG
- 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