|
| 1 | +--- |
| 2 | +title: "Set Log Levels" |
| 3 | +url: /refguide/log-levels/ |
| 4 | +description: "Describes how to configure the log levels for the various occurrence of logging within your app." |
| 5 | +aliases: |
| 6 | + - /howto/monitoring-troubleshooting/log-levels/ |
| 7 | +--- |
| 8 | + |
| 9 | +## Introduction |
| 10 | + |
| 11 | +Each application has a log to which it writes log messages to monitor the health of the running application. Log levels are used to label the log messages and to highlight the highest priority ones so that they can be easily identified and responded to. |
| 12 | + |
| 13 | +This how-to teaches you how to do the following: |
| 14 | + |
| 15 | +* Configure the log levels for the various types of logging within your app |
| 16 | + |
| 17 | +## Logging Basics |
| 18 | + |
| 19 | +### Log Messages |
| 20 | + |
| 21 | +Log messages appear in the log of your Mendix application and present contextualized and detailed information, including the following: |
| 22 | + |
| 23 | +* Date and time the log message was created |
| 24 | +* Level |
| 25 | +* Log node |
| 26 | +* Message |
| 27 | +* Stack trace |
| 28 | + |
| 29 | +#### Log Node |
| 30 | + |
| 31 | +The log node describes the source of the log message. For example, in a log message from the email module, the log node could be set to **Email Module**. |
| 32 | + |
| 33 | +#### Message |
| 34 | + |
| 35 | +Most messages in the log are auto-generated by the system (for example, **Mendix Runtime successfully started, the application is now available**). However, log messages that are created via a microflow, can be customized by the developer. |
| 36 | + |
| 37 | +Customized log messages are created by defining a **Template**. The template is the structure of the message, and can be composed of parameters and free text. |
| 38 | + |
| 39 | +{{< figure src="/attachments/refguide/runtime/log-levels/log-message-template.png" class="no-border" >}} |
| 40 | + |
| 41 | +In the image above, the template for the message is *Email not sent to department {1}*. With this example template, when the error occurs the customer’s email address is inserted into the parameter placeholder **{1}** (for example, the log message would be *Email not sent to department Customer Support*. Thus, the log message is customized with data that is specific to the error. |
| 42 | + |
| 43 | +#### Stack Trace |
| 44 | + |
| 45 | +The stack trace is a list of current method calls from the point when the application was started to the point where the exception occurred. |
| 46 | + |
| 47 | +In Studio Pro, log messages that include a stack trace are marked with a paperclip icon ({{% icon name="paperclip" %}}). Double-clicking this icon shows the stack trace. |
| 48 | + |
| 49 | +### Level {#level} |
| 50 | + |
| 51 | +The log level defines the severity of the log message. In Studio Pro, this is represented by different colors and an icon. |
| 52 | + |
| 53 | +These are the log levels used by Mendix: |
| 54 | + |
| 55 | +| Level | Icon | Color | Description |
| 56 | +| --- | --- | --- | --- | |
| 57 | +| Trace | | | More detailed information. These are only written to logs. | |
| 58 | +| Debug | | | Detailed information, typically of interest only when diagnosing problems. | |
| 59 | +| Info | | | Confirmation that things are working as expected. | |
| 60 | +| Warning | {{< figure src="/attachments/refguide/runtime/log-levels/warning.png" class="no-border" >}} | Orange | Indicates that something unexpected happened or that there is some problem in the near future (for example, "disk space low"). The application is still working as expected. | |
| 61 | +| Error | {{< figure src="/attachments/refguide/runtime/log-levels/error.png" class="no-border" >}} | Red | Due to a more serious problem, the application has not been able to perform some function. | |
| 62 | +| Critical | {{< figure src="/attachments/refguide/runtime/log-levels/critical.png" class="no-border" >}} | White (text), red (background) | A serious error has occurred, indicating that the application itself may be unable to continue running. | |
| 63 | + |
| 64 | +## Setting the Log Levels |
| 65 | + |
| 66 | +In this section you will learn how to specify which log messages are generated, based on the level of the log messages. Log messages with lower levels than the configured log level will not be generated. The different [levels](#level) can be applied both to the predefined logging produced by Mendix Studio Pro and to custom logging. |
| 67 | + |
| 68 | +### Configuring Log Levels via Script |
| 69 | + |
| 70 | +Log levels can be configured through the runtime admin port before the actual log levels exist. You can therefore create a script that sets all the required log levels at once. |
| 71 | + |
| 72 | +This is a Python script that sets `ConnectionBus` and `ActionManager` to the Trace and Debug levels, respectively: |
| 73 | + |
| 74 | +```py |
| 75 | +import requests, base64, json, sys |
| 76 | + |
| 77 | +payload = { |
| 78 | + 'action':'set_log_level', |
| 79 | + 'params': {'nodes' : [ |
| 80 | + { 'name':'ConnectionBus', 'level':'TRACE'}, |
| 81 | + { 'name':'ActionManager', 'level':'DEBUG'} |
| 82 | + ], 'force':True} |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +You can run this script as follows: |
| 87 | + |
| 88 | +```powershell |
| 89 | +C:\temp\LogDemoApp\python |
| 90 | +λ python setlogs.py 87a32a3e-c6db-4bc8-9fa3-7cd5b108eaec 8090 |
| 91 | +{"feedback":{},"result":0} |
| 92 | +``` |
| 93 | + |
| 94 | +### Configuring Log Levels Within Studio Pro {#configure-log-levels-from-studio-pro} |
| 95 | + |
| 96 | +To set the log levels within Studio Pro, follow these steps: |
| 97 | + |
| 98 | +1. Ensure that your app is running locally – if not, the option to set log levels will not be clickable. |
| 99 | +2. In the **Console** pane, click **Advanced** to open the menu of advanced options. |
| 100 | +3. Click **Set log levels**. |
| 101 | +4. For the relevant **Log node**, select the desired level from the drop-down in the **Log level** column. |
| 102 | + |
| 103 | +{{< figure src="/attachments/refguide/runtime/log-levels/set-log-levels.png" class="no-border" >}} |
| 104 | + |
| 105 | +{{% alert color="info" %}} |
| 106 | +You can override the log level for log messages in each environment when your app is deployed to Mendix Cloud. See the [Log Levels Tab](/developerportal/deploy/environments-details/#log-levels) section in *Environment Details* for more information. |
| 107 | +{{% /alert %}} |
| 108 | + |
| 109 | +## Setting the Log Levels for Custom Log Messages |
| 110 | + |
| 111 | +To set the level of custom log messages that you have created via a microflow, follow these steps: |
| 112 | + |
| 113 | +1. Open the microflow in which you intend to change the log message level. |
| 114 | +2. Double-click the log message activity. |
| 115 | +3. In the **Log level** drop-down, select the desired level. |
| 116 | + |
| 117 | +{{< figure src="/attachments/refguide/runtime/log-levels/custom-log-messages.png" class="no-border" >}} |
| 118 | + |
| 119 | +## Read More |
| 120 | + |
| 121 | +* [Find the Root Cause of Runtime Errors](/howto/monitoring-troubleshooting/finding-the-root-cause-of-runtime-errors/) |
| 122 | +* [Clear Warning Messages in Mendix](/howto/monitoring-troubleshooting/clear-warning-messages/) |
| 123 | +* [Monitor Mendix Using JMX](/howto/monitoring-troubleshooting/monitoring-mendix-using-jmx/) |
| 124 | +* [Debugging Microflows and Nanoflows](/refguide/debug-microflows-and-nanoflows/) |
| 125 | +* [Debug Java Actions](/howto/monitoring-troubleshooting/debug-java-actions/) |
0 commit comments