|
| 1 | +--- |
| 2 | +title: Set dynamic logger level to troubleshoot Java applications in Azure Container Apps (preview) |
| 3 | +description: Learn how to use dynamic logger level settings to debug your Java applications running on Azure Container Apps. |
| 4 | +services: container-apps |
| 5 | +author: craigshoemaker |
| 6 | +ms.service: container-apps |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 05/10/2024 |
| 9 | +ms.author: cshoe |
| 10 | +--- |
| 11 | + |
| 12 | +# Set dynamic logger level to troubleshoot Java applications in Azure Container Apps (preview) |
| 13 | + |
| 14 | +Azure Container Apps platform offers a built-in diagnostics tool exclusively for Java developers to help them debug and troubleshoot their Java applications running on Azure Container Apps more easily and efficiently. One of the key features is a dynamic logger level change, which allows you to access log details that are hidden by default. When enabled, log information is collected without code modifications or forcing you to restart your app when changing log levels. |
| 15 | + |
| 16 | +## Enable JVM diagnostics for your Java applications |
| 17 | + |
| 18 | +Before using the Java diagnostics tool, you need to first enable Java Virtual Machine (JVM) diagnostics for your Azure Container Apps. This step enables Java diagnostics functionality by injecting an advanced diagnostics agent into your app. Your app might restart during this process. |
| 19 | + |
| 20 | +To take advantage of these diagnostic tools, you can create a new container app with them enabled, or update an existing container app. |
| 21 | + |
| 22 | +To create a new container app with JVM diagnostics enabled, use the following command: |
| 23 | + |
| 24 | +```azurecli |
| 25 | +az containerapp create --enable-java-agent \ |
| 26 | + --environment <ENVIRONMENT_NAME> \ |
| 27 | + --resource-group <RESOURCE_GROUP> \ |
| 28 | + --name <CONTAINER_APP_NAME> |
| 29 | +``` |
| 30 | + |
| 31 | +To update an existing container app, use the following command: |
| 32 | + |
| 33 | +```azurecli |
| 34 | +az containerapp update --enable-java-agent \ |
| 35 | + --environment <ENVIRONMENT_NAME> \ |
| 36 | + --resource-group <RESOURCE_GROUP> \ |
| 37 | + --name <CONTAINER_APP_NAME> |
| 38 | +``` |
| 39 | + |
| 40 | +## Change runtime logger levels |
| 41 | + |
| 42 | +After enabling JVM diagnostics, you can change runtime log levels for specific loggers in your running Java app without the need to restart your application. |
| 43 | + |
| 44 | +The following sample uses the logger name `org.springframework.boot` with the log level `info`. Make sure to change these values to match your own logger name and level. |
| 45 | + |
| 46 | +Use the following command to adjust log levels for a specific logger: |
| 47 | + |
| 48 | +```azurecli |
| 49 | +az containerapp java logger update \ |
| 50 | + --logger-name "org.springframework.boot" \ |
| 51 | + --level "info" |
| 52 | + --environment <ENVIRONMENT_NAME> \ |
| 53 | + --resource-group <RESOURCE_GROUP> \ |
| 54 | + --name <CONTAINER_APP_NAME> |
| 55 | +``` |
| 56 | + |
| 57 | +It may take up to two minutes for the logger level change to take effect. Once complete, you can check the application logs from [log streams](log-streaming.md) or other [log options](log-options.md). |
| 58 | + |
| 59 | +## Supported Java logging frameworks |
| 60 | + |
| 61 | +The following Java logging frameworks are supported: |
| 62 | + |
| 63 | +- [Log4j2](https://logging.apache.org/log4j/2.x/) (only version 2.*) |
| 64 | +- [SLF4J](https://slf4j.org/) |
| 65 | +- [jboss-logging](https://github.com/jboss-logging/jboss-logging) |
| 66 | + |
| 67 | +### Supported log levels by different logging frameworks |
| 68 | + |
| 69 | +Different logging frameworks support different log levels. In the JVM diagnostics platform, some frameworks are better supported than others. Before changing logging levels, make sure the log levels you're using are supported by both the framework and platform. |
| 70 | + |
| 71 | +| Framework | Off | Fatal | Error | Warn | Info | Debug | Trace | All | |
| 72 | +|---------------|-------|-------|-------|------|------|-------|-------|-----| |
| 73 | +| Log4j2 | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | |
| 74 | +| SLF4J | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | |
| 75 | +| jboss-logging | No | Yes | Yes | Yes | Yes | Yes | Yes | No | |
| 76 | +| **Platform** | Yes | No | Yes | Yes | Yes | Yes | Yes | No | |
| 77 | + |
| 78 | +### General visibility of log levels |
| 79 | + |
| 80 | +| Log Level | Fatal | Error | Warn | Info | Debug | Trace | All | |
| 81 | +|-----------|-------|-------|------|------|-------|-------|-----| |
| 82 | +| **OFF** | | | | | | | | |
| 83 | +| **FATAL** | Yes | | | | | | | |
| 84 | +| **ERROR** | Yes | Yes | | | | | | |
| 85 | +| **WARN** | Yes | Yes | Yes | | | | | |
| 86 | +| **INFO** | Yes | Yes | Yes | Yes | | | | |
| 87 | +| **DEBUG** | Yes | Yes | Yes | Yes | Yes | | | |
| 88 | +| **TRACE** | Yes | Yes | Yes | Yes | Yes | Yes | | |
| 89 | +| **ALL** | Yes | Yes | Yes | Yes | Yes | Yes | Yes | |
| 90 | + |
| 91 | +## Related content |
| 92 | + |
| 93 | +> [!div class="nextstepaction"] |
| 94 | +> [Log steaming](./log-streaming.md) |
0 commit comments