Advanced Logging With Processes
Overview
In this lesson you will learn how to use advanced logging with an application process. This logging gets stored in the database, allowing administrators
- 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 connect an application to a database
- How to enable purging for database tables
- 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 Advanced Logging
Advanced logging is enabled as long as the relevant database table can be updated. Advanced logging uses the same ERROR, WARNING, DEBUG semantics as basic logging. However, logging to the database cannot be restricted as would be done for file logging. Therefore care should be taken to balance providing informative logs versus filling up the storage space allocated to the database.
If you run an application in development mode, then logs may also be copied into the application's file log. This is done purely for convenience, and is controlled at the level of the relevant log action, not the process.
Advanced Logging
All of the advanced logging stores the log messages in the database. Access these log entries is done from the corresponding admin function in the maintenance application.
Rather use the verbose forms such as ERROR or DEBUG, advanced logging will often use the short form instead.
- ERROR - 0
- WARNING - 1
- INFORMATION - 2
- DEBUG - 3
Application Process Log
This is used to produce general logs. These will most often be background tasks that need to report their status.
Task - You will be creating a process that will do the following with WriteApplicationProcessLogAction
- Log messages as it progresses
- Catch an exception
The inputs for the log message can be any of the following
-
Exception
- Type: Exception
- An exception that has been caught during the application flow
- If the action is provided with another message source the message in the exception will be ignored.
-
enactor.commonUI.logging.LogEntryType
- Type: Integer
- Set the enactor level to use for this log
- This is the numerical format stored in the database
-
enactor.coreUI.MessageBasename
- Type: String
- Define the message resource to use for resolving a message
-
enactor.coreUI.MessageId
- Type: String
- Define a predefined message to use
- The predefined message can also accept dynamic data
- These can be provided as custom inputs to the action
-
enactor.coreUI.Message
- Type: String
- Supply a custom message for the log
- This will always be used if provided
The following help to categorise and identify the nature of the log, which can be used to restrict the logs being viewed.
-
enactor.coreUI.DeviceId
- Type: String
- If provided, identifies the device that was executing the function
-
enactor.coreUI.UserId
- Type: String
- If provided, identifies the user involved with the function
- If the function is running in the background this should be the user that initiated the function
-
enactor.commonUI.logging.EntryType
- Type: String
- A broad categorisation, this gives a general indication of what function was executing
-
enactor.coreUI.ProcessId
- Type: String
- This categorisation provides additional debug information
- This will normally be the current process, but referring to an entry point process is also acceptable
-
enactor.coreUI.ReferenceId
- Type: String
- This categorisation is used to find logs related to a single invocation of a function
- Create a new application process called
DoApplicationLogs
- 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 WriteApplicationProcessLogAction called
LogProcessStart
- Link the
StateEntered
event from theStart
state to the actionLogProcessStart
- Define the
Message
to be 'The process has started' - Define the
LogEntryType
to be '3' (DEBUG) - Define the
EntryType
to be 'Training Task'
- Link the
- Add a WriteApplicationProcessLogAction called
LogProcessEndSuccess
- Link the action
LogProcessEndSuccess
to the End Process Action for outcome Success - Define the
Message
to be 'The process is ending successfully' - Define the
LogEntryType
to be '3' (DEBUG) - Define the
EntryType
to be 'Training Task'
- Link the action
- Add actions to load an entity
- Use the User entity
- Link the load entity action to
LogProcessEndSuccess
- Update
LogProcessEndSuccess
to include the loaded entity- Add an input for
enactor.coreUI.Entity
- Map this from the load action
- Update the
Message
forLogProcessEndSuccess
to be 'Loaded user{entity.userId}
. Process ending successfully.'
- Add an input for
- Add a WriteApplicationProcessLogAction called
LogEntityLoad
- Link action
LogProcessStart
toLogEntityLoad
- Link action
LogEntityLoad
to the actions to create the user key - Define the
Message
to be 'Preparing to load user' - Define the
LogEntryType
to be '2' (WARNING) - Define the
EntryType
to be 'Training Task'
- Link action
- Add a WriteApplicationProcessLogAction 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
Message
to be 'An exception occurred while loading the user' - Define the
LogEntryType
to be '0' (ERROR) - Define the
EntryType
to be 'Training Task'
- Link an Exception link from the load entity action to
- Execute the process
DoApplicationLogs
- Go to the maintenance application for Application Process Logs
- In the filter
Entry Type
enter 'Training Task' - Observe that the list is now restricted to logs for this process
Viewing the Application Process Log
The Application Process Log is normally located at Admin/Logs/ApplicationProcessLog
. The Application Process Log tracks a wide variety of information, so numerous filters are available to help narrow down which log entries to view.
The severity of the log is indicated in the column for type.
Activity Log
This is used to track changes made to entities by users. This log can retain the status from before and after the change, allowing an admin to revert undesired changes. These logs can be produced by a logged in user or the system user.
This log is only relevant when there may be a need to restore the previous state of an entity. This means that only applications intended to be a data management node will normally provide the functionality to access this log.
Viewing the Activity Log
The Activity Log is normally located at Admin/Logs/ActivityLog
. Simple filtering is available.
Each log entry can be viewed in multiple ways, allowing a user to see both the state of the entity before and after the change. This can be the normal view page for that entity, or as XML.
System Event Log
This is a low level log used by the application itself. Its purpose is to track when the status of the application changes, for instance when it last came online or when a user last logged on. Full details for handling system events is covered in the document "System Events".
System events are, primarily, logged in a centralised manner. A system event will be raised on a client application, such as a POS, and then sent to another application, such as the Estate Manager. This is, of course, reliant upon good network connectivity. If a client application cannot connect it will be unable to forward its system events.
To assist with potential investigations a client application can choose to keep a local copy of the log. To minimise confusion, the local copy is stored in the file system rather than the database. These are normally stored in the application Data home.
Task - Use the following actions to log your custom System Event.
CreateSystemEventLogEntryAction
SaveEntityToToFile
Viewing the System Event Log
The System Event Log is normally located at Admin/Logs/SystemEventLog
. System events from across the entire estate will be viewable here. These can be filtered to focus on particular types of events or those from a specific device.
System events do not contain any complex information, so all relevant information is presented in the list. For more detail, please refer to document on "System Events".