|
| 1 | +--- |
| 2 | +title: Azure Spring Cloud log streaming for instant availability |
| 3 | +description: How to use log streaming to view application logs instantly |
| 4 | +author: MikeDodaro |
| 5 | +ms.author: barbkess |
| 6 | +ms.service: spring-cloud |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 01/14/2019 |
| 9 | +--- |
| 10 | + |
| 11 | +# Azure Spring Cloud log streaming for instant availability |
| 12 | + |
| 13 | +The log streaming feature makes application logs available instantly using CLI with limited range. To view logs out of range, see [Analyze logs and metrics with diagnostics settings](./diagnostic-services.md). |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +* Install minimum version 0.2.0 of the [Azure CLI extension](https://docs.microsoft.com/azure/spring-cloud/spring-cloud-quickstart-launch-app-cli#install-the-azure-cli-extension) |
| 18 | +* An instance of **Azure Spring Cloud** with a running application, for example [Spring Cloud app](./spring-cloud-quickstart-launch-app-cli.md) |
| 19 | + |
| 20 | +## Use CLI to tail logs |
| 21 | + |
| 22 | +To avoid repeatedly specifying your resource group and service instance name, set your default resource group name and cluster name. |
| 23 | +``` |
| 24 | +az configure --defaults group=<service group name> |
| 25 | +az configure --defaults spring-cloud=<service instance name> |
| 26 | +``` |
| 27 | +In following examples, the resource group and service name will be omitted in the commands. |
| 28 | + |
| 29 | +### Tail log for app with single instance |
| 30 | +If an app named auth-service has only one instance, you can view the instance log with following command: |
| 31 | +``` |
| 32 | +az spring-cloud app log tail -n auth-service |
| 33 | +``` |
| 34 | +This will return logs: |
| 35 | +``` |
| 36 | +... |
| 37 | +2020-01-15 01:54:40.481 INFO [auth-service,,,] 1 --- [main] o.apache.catalina.core.StandardService : Starting service [Tomcat] |
| 38 | +2020-01-15 01:54:40.482 INFO [auth-service,,,] 1 --- [main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.22] |
| 39 | +2020-01-15 01:54:40.760 INFO [auth-service,,,] 1 --- [main] o.a.c.c.C.[Tomcat].[localhost].[/uaa] : Initializing Spring embedded WebApplicationContext |
| 40 | +2020-01-15 01:54:40.760 INFO [auth-service,,,] 1 --- [main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 7203 ms |
| 41 | +
|
| 42 | +... |
| 43 | +``` |
| 44 | + |
| 45 | +### Tail log for app with multiple instances |
| 46 | +If multiple instances exist for the app named `auth-service`, you can view the instance log by using the `-i/--instance` option. If the service auth-service has an instance named with auth-service-default-12-75cc4577fc-pw7hb, you can query with the following command. |
| 47 | +``` |
| 48 | +az spring-cloud app log tail -n auth-service -i auth-service-default-12-75cc4577fc-pw7hb |
| 49 | +``` |
| 50 | +You can also get the app instances from the Azure portal. |
| 51 | +1. Navigate to your Resource Group and select your Spring Cloud service. |
| 52 | +1. From the Spring Cloud service overview select **Apps** in the left navigation pane. |
| 53 | +1. Select your app, and then click **App Instances** in the left navigation pane. |
| 54 | +1. App instances will be displayed. |
| 55 | + |
| 56 | +### Follow switch to track new logs |
| 57 | +By default, CLI will only print the existing log to console without following new logs. If you need to track the new logs, use `-f(--follow)` to track the new logs: |
| 58 | +``` |
| 59 | +az spring-cloud app log tail -n auth-service -f |
| 60 | +``` |
| 61 | +### More options |
| 62 | +To see all the logging options supported: |
| 63 | +``` |
| 64 | +az spring-cloud app log tail -h |
| 65 | +``` |
| 66 | + |
| 67 | +## Next steps |
| 68 | + |
| 69 | +* [Analyze logs and metrics with diagnostics settings](./diagnostic-services.md) |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
0 commit comments