You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -6,8 +6,6 @@ The old-fashioned way is to write these messages into a log file, but that inher
6
6
7
7
On Docker v1.6, the concept of [**logging drivers**](https://docs.docker.com/engine/admin/logging/overview/) was introduced. The Docker engine is aware of the output interfaces that manage the application messages.
For Docker v1.8, we have implemented a native [**Fluentd Docker logging driver**](https://docs.docker.com/engine/admin/logging/fluentd/). Now, you are able to have a unified and structured logging system with the simplicity and high performance of [Fluentd](http://fluentd.org).
12
10
13
11
NOTE: Currently, the Fluentd logging driver doesn't support sub-second precision.
@@ -38,7 +36,7 @@ Create `demo.conf` with the following configuration:
38
36
bind 0.0.0.0
39
37
</source>
40
38
41
-
<match *>
39
+
<match **>
42
40
@type stdout
43
41
</match>
44
42
```
@@ -48,14 +46,16 @@ Create `demo.conf` with the following configuration:
2025-02-04 07:52:26 +0000 [info]: #0 listening port port=24224 bind="0.0.0.0"
75
+
2025-02-04 07:52:26 +0000 [info]: #0 fluentd worker is now running worker=0
76
76
```
77
77
78
78
### Step 3: Start Docker Container with Fluentd Driver
79
79
80
80
By default, the Fluentd logging driver will try to find a local Fluentd instance \(Step \# 2\) listening for connections on the TCP port `24224`. Note that the container will not start if it cannot connect to the Fluentd instance.
81
81
82
-

83
-
84
82
The following command will run a base Ubuntu container and print some messages to the standard output:
85
83
86
84
```text
87
-
$ docker run --log-driver=fluentd ubuntu echo "Hello Fluentd!"
88
-
Hello Fluentd!
85
+
$ docker run --log-driver=fluentd ubuntu echo "Hello Fluentd"
86
+
Hello Fluentd
89
87
```
90
88
91
89
Note that we have launched the container specifying the Fluentd logging driver i.e. `--log-driver=fluentd`.
@@ -95,7 +93,7 @@ Note that we have launched the container specifying the Fluentd logging driver i
95
93
Now, you should see the incoming messages from the container in Fluentd logs:
At this point, you will notice that the incoming messages are in JSON format, have a timestamp, are tagged with the `container_id` and contain general information from the source container along with the message.
@@ -105,6 +103,7 @@ At this point, you will notice that the incoming messages are in JSON format, ha
105
103
The application log is stored in the `"log"` field in the record. You can parse this log before sending it to the destinations by using [`filter_parser`](../filter/parser.md).
106
104
107
105
```text
106
+
# filter configuration
108
107
<filter docker.**>
109
108
@type parser
110
109
key_name log
@@ -113,50 +112,131 @@ The application log is stored in the `"log"` field in the record. You can parse
113
112
@type json # apache2, nginx, etc.
114
113
</parse>
115
114
</filter>
115
+
116
+
<source>
117
+
@type forward
118
+
port 24224
119
+
bind 0.0.0.0
120
+
</source>
121
+
122
+
<match **>
123
+
@type stdout
124
+
</match>
125
+
```
126
+
127
+
Then you provide the log message with JSON format:
128
+
129
+
```text
130
+
$ docker run --log-driver=fluentd --log-opt tag=docker ubuntu echo "{\"key\":\"value\"}"
116
131
```
117
132
118
-
Original Event:
133
+
About `--log-opt tag=...`, please refer at [Driver Options](#driver-options) section.
The application log is stored in the `log` field of the record. You can concatenate these logs by using [`fluent-plugin-concat`](https://github.com/fluent-plugins-nursery/fluent-plugin-concat) filter before sending it to the destinations.
133
150
151
+
At first, you need to create custom docker image due to install the `fluent-plugin-concat` gem in the Fluentd container.
152
+
153
+
Create `Dockerfile` with the following content:
154
+
155
+
```text
156
+
# Dockerfile
157
+
FROM fluent/fluentd:edge-debian
158
+
159
+
USER root
160
+
RUN fluent-gem install fluent-plugin-concat
161
+
162
+
USER fluent
163
+
```
164
+
165
+
Build the custom image:
166
+
167
+
```text
168
+
$ docker build . -t fluentd-test
169
+
```
170
+
171
+
Then, create the configuration file `demo.conf` with the following content:
If the logs are typical stacktraces, consider using [`detect-exceptions`](https://github.com/GoogleCloudPlatform/fluent-plugin-detect-exceptions) plugin instead.
159
221
222
+
**NOTE**:
223
+
For plugins with the simple file structure, such as `fluent-plugin-concat`, `plugins` directory can be used instead of creating custom docker image.
224
+
225
+
Prepare the `plugins` directory and copy the plugin file:
The [Fluentd Logging Driver](https://docs.docker.com/engine/admin/logging/fluentd/) supports following options through the `--log-opt` Docker command-line argument:
0 commit comments