Get started with Team Logs ΒΆ

Team Logs is a private logging solution leveraging Google Cloud Logs. It provides your team with a secure, isolated log storage system, ensuring logs are not mixed with those of other teams.

How to Configure Team Logs ΒΆ

To send logs to your team's private index, configure your application to use the team-logs appender. This configuration is typically done in your logback.xml or log4j.xml.

xml

NB! Marker is not required for the team-logs appender, but it is recommended to use it to ensure that logs are sent to the correct destination. In this configuration the default-json appender will send all logs that do not have the TEAM_LOGS marker to the console.

You also need to add the following dependency to your pom.xml:

xml
xml

NB! Marker is not required for the team-logs appender, but it is recommended to use it to ensure that logs are sent to the correct destination. In this configuration the default-json appender will send all logs that do not have the TEAM_LOGS marker to the console.

The referenced environment variables are set automatically in your application, so you don't need to configure them manually.

This configuration ensures that all logs are sent exclusively to your team's private log index on Google Cloud.

Nais.yaml Configuration ΒΆ

You also need to configure your nais.yaml file to allow the application to send logs to the team-logs appender. This is done by adding the following configuration:

yaml

Other Logging Libraries ΒΆ

You can use other logging libraries that support JSON format and TCP/HTTP output.

  • TCP: team-logs.nais-system:5170
  • HTTP: team-logs.nais-system:80

The format for the logs should be JSON, and you must include the following fields:

Field NameDescriptionEnvironment Variable
google_cloud_projectThe Google Cloud project IDGOOGLE_CLOUD_PROJECT
nais_namespace_nameThe namespace of the applicationNAIS_NAMESPACE
nais_pod_nameThe name of the podNAIS_POD_NAME
nais_container_nameThe name of the containerNAIS_APP_NAME
messageThe log message
severityThe log level (e.g., INFO, ERROR)

Migrating from Secure Logs ΒΆ

If you are migrating from Secure Logs to Team Logs, you need to ensure that your application is configured to send logs to the team-logs appender instead of the Secure Logs appender. This involves updating your logging configuration files (logback.xml or log4j2.xml) and ensuring that the necessary dependencies are included in your project.

It is possible to use both Secure Logs and Team Logs simultaneously, but it is only recommended to do so temporarily during the migration process. Once you have confirmed that your logs are being sent correctly to Team Logs, you should remove the Secure Logs configuration from your application.

Once you have completely migrated to Team Logs you should also remove any references to Secure Logs in your nais.yaml configuration - specifically the secureLogs section.

Writing Logs ΒΆ

To ensure that your logs are sent to the team-logs appender, you can use SLF4J markers or loggers. Below are detailed examples of how to do this in both Logback and Log4j2.

If you are using Logback, you can use the team-logs appender in your logging configuration. You can also use SLF4J markers to route specific log messages to the team-logs appender.

Below is an example in Kotlin using an SLF4J marker to ensure your log messages are routed to the "team-logs" appender:

kotlin

Ensure that your logback.xml configuration includes the team-logs appender and the marker-based filter as shown in the configuration section above.

If you are using Log4j2, you can use the team-logs appender in your logging configuration. You can also use markers to route specific log messages to the team-logs appender.

Below is an example in Kotlin using a Log4j2 marker to ensure your log messages are routed to the "team-logs" appender:

kotlin

Ensure that your log4j2.xml configuration includes the team-logs appender and the marker-based filter as shown in the configuration section above.

If you are using a logging library that does not support SLF4J or Log4j2, you can still send logs to the team-logs appender using a simple HTTP request. Below is an example using curl:

bash

Key Points for Developers ΒΆ

  1. Markers: Use the TEAM_LOGS marker to route logs to the team-logs appender. Without this marker, logs will go to the default JSON appender.
  2. Error Handling: Always log errors with appropriate severity levels (e.g., error, warn) to ensure they are easily identifiable.
  3. Structured Logging: Use JSON format for logs to make them easier to query and analyze.
  4. Configuration: Ensure your logging configuration files (logback.xml or log4j2.xml) are correctly set up with the team-logs appender and marker-based filters.

Accessing Team Logs ΒΆ

Team Logs can be accessed through the Google Cloud Console or other tools that support Google Cloud Logging. Note that Team Logs are kept separate from standard log destinations like Grafana Loki and thus aren’t available through its standard logging interface.

Querying Team Logs ΒΆ

To search your logs, use the Google Cloud Logging Query Language. Here are some practical examples:

  • Filter by app name:

    Plaintext
  • Filter by severity:

    Plaintext
  • Combine multiple filters:

    Plaintext
  • Filter by a specific time range:

    Plaintext

For more detailed guidance, review the following resources:

Log Labels ΒΆ

Team Logs automatically attaches labels to every log entry for better context. Below are some key labels you’ll see:

json

This structure ensures that you can easily locate and analyze your team's logs with clarity and precision.