What is logging?
Logging can be defined as the process of recording events or actions that occur during the execution of a workflow. It involves creating log messages that contain details such as process start/end, timestamps, error messages, severity levels of messages, user inputs, or any other information relevant to an action and then storing them in a Log file.
Effective logging practice is an essential part of developing automation as it helps understand the flow of execution of workflows and identify the cause of errors or unexpected behaviors.
Types of logs in UiPath
Before we learn how to set up logs that are useful when developing projects, let's first start by checking out the main types of logs generated by the UiPath Platform:
- Studio logs.
- Setup Logs
- Orchestrator diagnostic logs.
- Robot Logs
Robot logs
There are two types of Robot logs:
Robot execution logs: These are messages generated by the execution of a process and contain information related to its behavior and user-defined messages.
Robot diagnostics log: These provide information related to the Robot itself and its context.
Our focus will be on the robot execution logs as they can be used to supervise, diagnose, and debug processes in production, and gather process performance data.
Robot execution logs can either be default logs or user-defined logs.
Default logs are generated automatically when certain events take place. These events can be the start/end of a process or a transaction, encountering an error, or when the Robot Logging Setting is set to Verbose.
- Execution start is generated every time a process is started (Level = Information).
- Execution end is generated every time a process is finalized (Level = Information).
- Transaction start is generated every time a transaction within a process is started (Level = Information).
- Transaction end is generated every time a transaction within a process is finalized (Level = Information).
- Error log is generated every time the execution encounters an error and stops (Level = Error).
- Debugging log is generated if the Robot Logging Setting is set to Verbose, and contains, Activity names, types, variable values, arguments, etc. (Level = Trace).
- User-defined logs are generated according to the process designed by you in Studio when using Log Message Activity or Write Line Activity.
Logging levels in UiPath
Each log has a Log Level that refers to how important the generated message is. In other words, logging levels let you sort log messages by severity, or by how important a log message is related to the execution of a process. Log levels are used in Orchestrator to filter out logs below a specific level.
Given below is a list of log levels in descending order of their priority along with their meaning.
Fatal/ Critical:
The robot cannot or shouldn't recover from this error. Something has gone critically wrong, and the process needs to stop.
Error
An error has occurred. The robot will try to recover and move on with the next item.
Warning
Any important data that you need to stand out from the rest of the log information.
Information
Information about robot progress. Usually includes when you enter/exit a workflow, when data is read from an external source, etc.
Trace
Information that's useful while developing/debugging, however not useful and needed in production.
Debugging/Verbose level
Verbose level generates default logs for the execution of each Activity, allowing a much more in-depth diagnosis by giving more information about the values of variables and arguments.
Summary
The types of logs generated by the UiPath Platform are:
Studio logs
Setup logs
Orchestrator diagnostics logs
Robot logs
The process of gathering and storing logs generated during the execution of a workflow is called Logging.
Robot execution logs and Robot diagnostic logs are the two types of Robot logs.
Robot execution logs are used to supervise, diagnose, and debug processes in production or gather process performance data. These logs can either be default logs or user-defined logs.
The priority order of the log types is: Verbose < Trace < Information < Warning < Error < Critical
Accessing logs
There are several places where you can access Robot Execution Logs:
- In the Output Panel in UiPath Studio for the previous process execution from Studio.
- In the %localappdata%\UiPath\Logs\<shortdate>_Execution.log file for all processes ran on the machine from UiPath Studio. Logs are generated at Trace level and above or Verbose level and above depending on whether the Verbose level is activated or not.
- In the %localappdata%\UiPath\Logs\<shortdate>_Execution.log file for all processes ran on the machine from UiPath Assistant. The logs are generated at the level defined in UiPath Assistant and above.
- In Orchestrator, in the Logs section when running processes while connected to Orchestrator. The logs are generated at the defined level and above.
The anatomy of a log entry
Let's now understand how log entries are structured. These entries can be very helpful when checking execution logs to analyze behavior or figure out what caused an exception. Logs are in the form of a JSON, pretty much just a key-value pair (“field1:value1,” “field2:value2”).
The default log fields are present in all logs:
Message: The log message.
Level: The log severity of the log message.
Timestamp: The exact date and time the action was performed.
FileName: The name of the .xaml file being “executed".
JobId: The key of the job running the process.
ProcessName: The name of the process that triggered the logging.
ProcessVersion: The version number of the process.
WindowsIdentity: The name of the user that performed the action that was logged.
RobotName: The name of the robot (as defined in Orchestrator).
Aside from default fields, logs can also contain type-specific fields and user-defined fields.
- Type-specific fields are present depending on the log type, like totalExecutionTimeInSeconds and totalExecutionTime for Execution End.
- User-defined fields are defined in Studio (by using the Add Log Fields Activity) and appear in all resulting logs after the activity is generated unless they are (programmatically) removed by the activity Remove Log Fields.
Setting the log level for UiPath Assistant
Running a process from UiPath Assistant will send the logs to Orchestrator if connected, but also generate logs in %localappdata%\UiPath\Logs\<shortdate>_Execution.log.
The log entries are generated at the level set in UiPath Assistant and above. For example, if the level is set to Error, it'll only generate the logs at the Error and Fatal levels.
The next example shows you how to configure the UiPath Assistant to log events at the Information level and above for processes executed through it.
- Open UiPath Assistant and click the Preference icon.
- Click the Preferences button.
- Click the Orchestrator Setting option.
- Click the Log Level drop-down.
- Select the Information option.
- Click Close, and you're done.
From now on, UiPath Assistant will save logs only at the Information level and above, both locally and in Orchestrator.
Logging recommendations
When diagnosing a process in production, you'll find that oftentimes, the default exception log messages are helpful, but not enough to provide a full picture of why it's failing. User-defined logs are the breadcrumbs you can use to track your robot's progress through the process and get a better view of the execution.
On the other hand, over-logging can increase the load on Orchestrator, slow your process down, and make it hard to diagnose an issue because of the sheer volume of log entries.
The solution is to define the right log messages at strategic points in your project. The recommendations below cover some healthy uses for identifying events that could lead to issues.
Log message activities should ideally be used in the following scenarios:
- Each time an exception is caught in a Catch block (Log level = Error).
- Each time a Business Rule Exception is thrown (Log Level = Error).
- When data is read from external sources. For example, log a message at Information level when an Excel file is read (Log Level = Information).
- In Parallel or Pick activities, log messages on every branch, to trace the branch is taken (Log Level = Information).
- In If/Flowchart Decision/Switch/Flow Switch activities.
Note: There should be no more than two (maximum three) nested IF statements so it depends from workflow to workflow if you should add or not log message activities.
When you invoke a workflow use the two properties Log Entry and Log Exit (Log level = Information). These let you specify if you want to log entry into/ exit from an invoked workflow. This is particularly useful for debugging without adding lots of Log Message activities.
Write meaningful log messages: The message should be clear enough.
Add context to your log message: Include values of meaningful variables in that context.
Source: UiPath Academy
Comments
Post a Comment