---
title: Fluentd plugin for log forwarding
source: https://docs.newrelic.com/docs/logs/forward-logs/fluentd-plugin-log-forwarding
---

If your log data is already being monitored by [Fluentd](https://www.fluentd.org), you can use our Fluentd integration to forward and enrich your log data in New Relic.

Forwarding your Fluentd logs to New Relic will give you enhanced log management capabilities to collect, process, explore, query, and alert on your log data.

## Basic process [#enable-process]

To enable log management capabilities:

1.  Make sure you have:

    -   A New Relic license key
    -   Fluentd 1.0 or higher

2.  [Install](#fluentd-plugin) the Fluentd plugin.

3.  [Configure](#configure-plugin) the Fluentd plugin.

4.  If applicable, [configure EU or Japan endpoint](#eu-configuration)

5.  [Test](#test-plugin) the Fluentd plugin.

6.  Generate some traffic and wait a few minutes, then [check your account](#find-data) for data.

## Install the Fluentd plugin [#fluentd-plugin]

To install the Fluentd plugin:

**Install using fluent-gem install**

To install using `fluent-gem install`, enter the following command into your terminal or command line interface:

````shell
fluent-gem install fluent-plugin-newrelic
```

````

**Install using td-agent-gem**

To install using the [td-agent](https://docs.fluentd.org/quickstart/td-agent-v2-vs-v3) plugin, enter the following command into your terminal or command line interface:

````shell
td-agent-gem install fluent-plugin-newrelic
```

````

## Configure the Fluentd plugin [#configure-plugin]

> #### 💡 TIP
>
> If you're configuring Fluentd for the first time, you may find it helpful to review our collection of pre-built [configuration files](https://github.com/newrelic/newrelic-fluentd-output/tree/master/examples) addressing common use cases.

To configure your Fluentd plugin:

1.  In your `fluent.conf` file, or `td-agent.conf` if using the td-agent, add the following block of data, replacing the placeholder text with your license key:

    ```apacheconf
    #Tail one or more log files
    <source>
      @type tail
      <parse>
        @type none
      </parse>
      path /path/to/file
      tag example.service
    </source>

    #Add hostname and service_name to all events with "example.service" tag
    <filter example.service>
      @type record_transformer
      <record>
        service_name ${tag}
        hostname "#{Socket.gethostname}"
      </record>
    </filter>

    #Forward all events to New Relic

    <match>
      @type newrelic
      license_key YOUR_LICENSE_KEY
    </match>
    ```

2.  Restart the Fluentd service to ensure your changes are applied.

## Configure the Fluentd Plugin for EU or Japan accounts [#eu-configuration]

By default the Fluentd plugin forwards logs to our US endpoint: `https://log-api.newrelic.com/log/v1`. If your New Relic organization is in our [EU or Japan data center](https://docs.newrelic.com/docs/accounts/accounts-billing/account-setup/choose-your-data-center), you must manually set the `base_uri` property to the appropriate endpoint:

-   EU: `https://log-api.eu.newrelic.com/log/v1`
-   Japan: `https://log-api.jp.nr-data.net/log/v1`

For example, to forward logs to the EU endpoint:

```apacheconf
#Tail one or more log files
<source>
  @type tail
  <parse>
    @type none
  </parse>
  path /path/to/file
  tag example.service
</source>

#Add hostname and service_name to all events with "example.service" tag
<filter example.service>
  @type record_transformer
  <record>
    service_name ${tag}
    hostname "#{Socket.gethostname}"
  </record>
</filter>

#Forward all events to New Relic EU Endpoint
<match>
  @type newrelic
  license_key YOUR_LICENSE_KEY
  base_uri https://log-api.eu.newrelic.com/log/v1
</match>
```

For Japan accounts, replace the `base_uri` in the `<match>` block with the Japan endpoint:

```apacheconf
#Forward all events to New Relic Japan Endpoint
<match>
  @type newrelic
  license_key YOUR_LICENSE_KEY
  base_uri https://log-api.jp.nr-data.net/log/v1
</match>
```

## Test the Fluentd plugin [#test-plugin]

To test if your Fluentd plugin is receiving input from a log file:

1.  Run the following command to append a test log message to your log file:

    ```shell
    echo "test message" >> /PATH/TO/YOUR/LOG/FILE
    ```

2.  Search our [logs UI](https://one.newrelic.com/launcher/logger.log-launcher) for `test message`.

## View log data [#find-data]

If everything is configured correctly and your data is being collected, you should see logs in both of these places:

-   Our [logs UI](https://one.newrelic.com/launcher/logger.log-launcher)
-   Our tools for running [NRQL queries](https://docs.newrelic.com/docs/chart-builder/use-chart-builder/choose-data/use-advanced-nrql-mode-specify-data). For example, you can execute a query like this:

```sql
SELECT * FROM Log
```

If no data appears after you enable our log management capabilities, follow our [standard log troubleshooting procedures](https://docs.newrelic.com/docs/logs/log-management/troubleshooting/no-log-data-appears-ui/).

## Tune up log Fluentd buffer [#tuneup-buffer]

By default, the plugin sends logs to New Relic every five seconds. If you want to change this timing, add a `<buffer>` block to the configuration by following this example:

```apacheconf
[...]

# Forward all events to New Relic
# For EU accounts set base_uri to https://log-api.eu.newrelic.com/log/v1
# For Japan accounts set base_uri to https://log-api.jp.nr-data.net/log/v1
<match>
  @type newrelic
  license_key YOUR_LICENSE_KEY

  <buffer time>
    timekey 60s
  </buffer>
</match>
```

For more information, see the [Fluentd documentation about buffer configurations](https://docs.fluentd.org/configuration/buffer-section).

## Configure UTF-16LE to UTF-8 transformation [#configure-utf-16le]

In this example for Microsoft SQL Server error logs, use Fluentd to send [UTF-16LE](https://docs.fluentd.org/input/tail#encoding-from_encoding) encoded logs to New Relic with the [required UTF-8 encoding](https://docs.newrelic.com/docs/data-apis/custom-data/custom-events/data-requirements-limits-custom-event-data/#general) for ingest. You can also adopt this example to other encodings.

> #### 💡 TIP
>
> We also add an appropriate `logtype` for these logs.

```apacheconf
#Tail one or more log files
<source>
  @type tail
  <parse>
    @type none
  </parse>
  path "D:/sqlserver/error.log"
  tag example.service
  encoding UTF-8
  from_encoding UTF-16LE
</source>

#Add hostname and service_name to all events with "example.service" tag
<filter example.service>
  @type record_transformer
  <record>
    service_name ${tag}
    hostname "#{Socket.gethostname}"
    logtype MSSQL
  </record>
</filter>

#Forward all events to New Relic
<match>
  @type newrelic
  license_key YOUR_LICENSE_KEY
</match>
```

## Configure Shift-JIS to UTF-8 transformation

Japanese log files encoded in Shift-JIS (CP932) are converted to the [required UTF-8 encoding](https://docs.newrelic.com/docs/data-apis/custom-data/custom-events/data-requirements-limits-custom-event-data/#general) and are required for importing and sending log data to New Relic.

```apacheconf

<source>
#Tail one or more log files
  @type tail
  path C:¥opt¥fluent¥cp932text.log  # Full path of the log file you want to collect
  tag example.service
  from_encoding CP932 #logFile character encoding
  encoding UTF-8 #Character encoding when sending to New Relic
  <parse>
    @type none
  </parse>
</source>

#Forward all events to New Relic
<match>
  @type newrelic
  license_key YOUR_LICENSE_KEY
</match>

```

## What's next? [#what-next]

Explore logging data across your platform with our [logs UI](https://docs.newrelic.com/docs/logs/log-management/ui-data/use-logs-ui/).

-   Get deeper visibility into both your application and your platform performance data by forwarding your logs with our [logs in context](https://docs.newrelic.com/docs/logs/enable-log-management-new-relic/configure-logs-context/configure-logs-context-apm-agents/) capabilities.
-   Set up [alerts](https://docs.newrelic.com/docs/alerts-applied-intelligence/new-relic-alerts/alert-conditions/create-alert-conditions/).
-   [Query your data](https://docs.newrelic.com/docs/query-your-data/explore-query-data/get-started/introduction-querying-new-relic-data/) and [create dashboards](https://docs.newrelic.com/docs/query-your-data/explore-query-data/dashboards/introduction-dashboards/).

## Disable log forwarding [#disable]

To disable log forwarding capabilities, follow standard procedures in [Fluentd documentation](https://www.fluentd.org). You do not need to do anything else in New Relic.
