---
title: "Log Aggregation to Datadog"
description: "How to configure logging to Datadog"
url: "https://curity.io/resources/learn/log-to-datadog/"
date: "2020-09-24"
area: "tutorials"
topic: "howtos"
pagegroup: "logging-monitoring"
---

# Log Aggregation to Datadog

Datadog is a popular monitoring service. This article focuses on how to send logs from Curity Identity Server to Datadog.

## Prerequisites

This tutorial covers how to configure Curity Identity Server with Datadog. If you need specific help with Datadog, please refer to their [documentation](https://docs.datadoghq.com/).

The [documentation of the Curity Identity Server](https://curity.io/docs/identity-server/system-and-operation/operation-and-monitoring/logging/) also outline general information on how to configure logging.

## Configuring Curity Identity Server

Logs must be in JSON format to be consumed by Datadog.

Curity Identity Server offers much flexibility when it comes to logging. You can specify different log settings for various parts of the product. For example, you can enable low-level logging for a specific element. You can have some logs written to files and others sent to Datadog.

Curity Identity Server uses [Log4j 2](https://logging.apache.org/log4j/2.x/manual/), a logging framework. You can change the log settings by editing `$IDSVR_HOME/etc/log4j2.xml`.

Using Docker

If you are using Docker, you can either mount your modified log4j2.xml file or create your own image based on ours but with updated log settings.

In this file, we will create a new `Appender` that logs in JSON format. Keep in mind; the strategy is slightly different if you are running in a container or have Curity Identity Server binaries directly.

**Binary install**

If installed locally, we will send the logs to a file. The Datadog agent will then tail this file.

```xml
<RollingFile name="datadog-log" fileName="${env:IDSVR_HOME}/var/log/datadog.log" filePattern="${env:IDSVR_HOME}/var/log/datadog.log.%i.gz">
    <Policies>
        <SizeBasedTriggeringPolicy size="10MB"/>
    </Policies>
    <JSONLayout compact="true" eventEol="true" properties="true" stacktraceAsString="true"/>
</RollingFile>
```

**Container**

In a container environment, you send logs to standard out to be picked up by the Datadog agent.

```xml
<Console name="datadog-log" target="SYSTEM_OUT">
    <JSONLayout compact="true" eventEol="true" properties="true" stacktraceAsString="true"/>
</Console>
```

### Using the Appender

Once we have an appender, we must select which `Loggers` will use it.

Since Curity Identity Server offers logging flexibility, there are multiple `Loggers` in the `log4j2.xml` file. You configure which appender to use by setting the `AppenderRef` property.

To set the main server log to use the new Datadog appender, it would look something like this:

```xml
<AsyncLogger name="se.curity" level="INFO">
    <AppenderRef ref="datadog-log"/>
</AsyncLogger>
```

You can use the same `Appender` to many (or all) `Loggers`.

You can also have multiple `Appenders` attached to a `Logger`. Just add an extra `AppenderRef`.

## Setting up the Datadog Agent

The Datadog agent is responsible for transporting logs to Datadog. This agent is configured a bit differently, depending on your environment.

**Binary install**

In the case of a local install of Curity Identity Server, you install the agent in the same way.

Start by installing the agent:

```bash
DD_AGENT_MAJOR_VERSION=7 DD_API_KEY=[YOUR_KEY] DD_SITE="datadoghq.[eu|com]" bash -c "$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script.sh)"
```

Then, you must configure it. First, enable log management. This is done by editing `/etc/datadog-agent/datadog.yaml`.

Set the following:

```yml
logs_enabled: true
```

You must also set up where to find your logs. Create the file `/etc/datadog-agent/conf.d/java.yaml` with the following content:

```yml
logs:
- type: file
    path: "<IDSVR_HOME>/var/log/datadog.log"
    service: java
    source: java
    sourcecategory: sourcecode
```

Make sure to replace `<IDSVR_HOME>` with your installation directory of Curity Identity Server.

Lastly, restart the agent:

```bash
sudo systemctl stop datadog-agent
sudo systemctl start datadog-agent
```

**Docker**

In the case of Docker, you log to standard out, and the agent runs a separate container. Start the agent container with the following command:

```bash
docker run --rm -d --name dd-agent -v /var/run/docker.sock:/var/run/docker.sock:ro -v /proc/:/host/proc/:ro -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro -e DD_API_KEY=[YOUR_KEY] -e DD_SITE="datadoghq.[eu|com]" -e DD_LOGS_ENABLED=true -e DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true -e DD_CONTAINER_EXCLUDE_LOGS="name:dd-agent" datadog/agent:7
```

This command will send logs from all containers except the agent itself.

**Kubernetes**

In Kubernetes, we install the agent by using helm. First, you need a settings file. [Download](https://github.com/DataDog/helm-charts/blob/master/charts/datadog/values.yaml) the default values file and name it `datadog-values.yaml`.

Next, open the file and enable log collecting by modifying the following values:

```yml
logs:
    enabled: true
    containerCollectAll: true
    containerCollectUsingFiles: false
```

To install the agent, run:

```bash
helm install datadog -f datadog-values.yaml --set datadog.site='datadoghq.[eu|com]' --set datadog.apiKey=[YOUR_KEY] datadog/datadog
```

Trusted certificates

If you are not using trusted certificates in your Kubernetes installation, the agent might fail to read logs. If you encounter a problem, set the `DD_KUBELET_TLS_VERIFY` environment variable to `false` for the agent to skip verification.

**Other environments**

Using the `Appenders` above will ensure Curity Identity Server creates correct logs for Datadog. See the [Agent Docs](https://docs.datadoghq.com/agent/) for more information on setting up the agent in other environments.

## Conclusion

The setup above will send both logs and system metrics to Datadog. You can also connect Datadog to the [metrics provided by Curity Identity Server](https://curity.io/docs/identity-server/system-and-operation/operation-and-monitoring/prometheus-compliant-metrics/).

Also, by utilizing multiple Loggers, you can choose which logs to send to Datadog. For example, you can log sensitive data to a file instead of sending it to Datadog.
