Skip to content

Commit 25d38fc

Browse files
authored
Merge pull request #416 from daipom/use-yaml-syntax-for-codeblock
Use yaml syntax
2 parents b79d3ad + f3b3395 commit 25d38fc

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

configuration/config-file-yaml.md

+23-23
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Let's actually create a configuration file step by step.
5656

5757
Fluentd input sources are enabled by selecting and configuring the desired input plugins using **source** elements. Fluentd standard input plugins include `http` and `forward`. The `http` provides an HTTP endpoint to accept incoming HTTP messages whereas `forward` provides a TCP endpoint to accept TCP packets. Of course, it can be both at the same time. You may add multiple `source` configurations as required.
5858

59-
```text
59+
```yaml
6060
config:
6161
# Receive events from 24224/tcp
6262
# This is used by log forwarding and the fluent-cat command
@@ -80,7 +80,7 @@ You can add new input sources by writing your own plugins. For further informati
8080

8181
The **match** element looks for events with **match**ing tags and processes them. The most common use of the `match` element is to output events to other systems. For this reason, the plugins that correspond to the `match` element are called **output plugins**. Fluentd standard output plugins include `file` and `forward`. Let's add those to our configuration file.
8282

83-
```text
83+
```yaml
8484
config:
8585
# Receive events from 24224/tcp
8686
# This is used by log forwarding and the fluent-cat command
@@ -117,7 +117,7 @@ Input -> filter 1 -> ... -> filter N -> Output
117117

118118
Let's add standard `record_transformer` filter to `match` example.
119119

120-
```text
120+
```yaml
121121
config:
122122
# http://this.host:9880/myapp.access?json={"event":"data"}
123123
- source:
@@ -153,7 +153,7 @@ System-wide configurations are set by `system` element. Most of them are also av
153153

154154
Example:
155155

156-
```text
156+
```yaml
157157
system:
158158
# equal to -qq option
159159
log_level: error
@@ -168,7 +168,7 @@ See also [System Configuration](../deployment/system-config.md) article for more
168168

169169
If this parameter is set, fluentd supervisor and worker process names are changed.
170170

171-
```text
171+
```yaml
172172
system:
173173
process_name: fluentd1
174174
```
@@ -191,7 +191,7 @@ The `label` element's parameter is a builtin plugin parameter so `$name` paramet
191191

192192
Here is a configuration example:
193193

194-
```text
194+
```yaml
195195
config:
196196
- source:
197197
$type: forward
@@ -253,7 +253,7 @@ See [Multi Process Workers](../deployment/multi-process-workers.md) article for
253253

254254
Here is a configuration example:
255255

256-
```text
256+
```yaml
257257
system:
258258
workers: 4
259259
@@ -306,15 +306,15 @@ The outputs of this config are as follows:
306306

307307
The element in separate configuration files can be imported using the **!include** element:
308308

309-
```text
309+
```yaml
310310
config:
311311
# Include config files in the ./config.d directory
312312
- !include config.d/*.conf
313313
```
314314

315315
The `!include` YAML tag supports regular file path, glob pattern, and http URL conventions:
316316

317-
```text
317+
```yaml
318318
config:
319319
# absolute path
320320
- !include /path/to/config.conf
@@ -333,7 +333,7 @@ config:
333333

334334
Note that for the glob pattern, files are expanded in alphabetical order. If there are `a.conf` and `b.conf` then fluentd parses `a.conf` first. But, you should not write the configuration that depends on this order. It is so error-prone, therefore, use multiple separate `!include` YAML tags for safety.
335335

336-
```text
336+
```yaml
337337
config:
338338
# If you have a.conf, b.conf, ..., z.conf and a.conf / z.conf are important
339339
@@ -350,7 +350,7 @@ config:
350350

351351
The `!include` YAML tag can be used under sections to share the same parameters:
352352

353-
```text
353+
```yaml
354354
# config file
355355
config:
356356
- match:
@@ -381,7 +381,7 @@ Note that, in the middle of element case of `!include` YAML tag usage, users mus
381381

382382
Fluentd tries to match tags in the order that they appear in the config file. So, if you have the following configuration:
383383

384-
```text
384+
```yaml
385385
config:
386386
# '**' matches all tags. Bad :(
387387
- match:
@@ -396,7 +396,7 @@ config:
396396

397397
then `myapp.access` is never matched. Wider match patterns should be defined after tight match patterns.
398398

399-
```text
399+
```yaml
400400
config:
401401
- match:
402402
$tag: myapp.access
@@ -413,7 +413,7 @@ Of course, if you use two same patterns, the second `match` is never matched. If
413413

414414
The common pitfall is when you put a `filter` element after `match` element. It will never work since events never go through the filter for the reason explained above.
415415

416-
```text
416+
```yaml
417417
config:
418418
# You should NOT put this <filter> block after the <match> block below.
419419
# If you do, Fluentd will just emit events without applying the filter.
@@ -433,7 +433,7 @@ config:
433433

434434
When using YAML format syntax in Fluentd configuration, you can use `!fluent/s "#{...}"` to embed arbitrary Ruby code into match patterns. Here is an example:
435435

436-
```text
436+
```yaml
437437
config:
438438
- match:
439439
$tag: fluent/s "app.#{ENV['FLUENTD_TAG']}"
@@ -466,7 +466,7 @@ This section describes some useful features for the configuration file.
466466

467467
You can write multiline values for `"` quoted string, array and hash values.
468468

469-
```text
469+
```yaml
470470
str_param: "foo # Converts to "foo bar". As NL interpretation will be required for continuos newlines.
471471
bar"
472472
@@ -488,7 +488,7 @@ Fluentd assumes `[` or `{` is a start of array / hash. So, if you want to set `[
488488

489489
Example \# 1: mail plugin
490490

491-
```text
491+
```yaml
492492
config:
493493
- match:
494494
$tag: '**'
@@ -498,7 +498,7 @@ config:
498498

499499
Example \# 2: map plugin
500500

501-
```text
501+
```yaml
502502
config:
503503
- match:
504504
$tag:tag
@@ -514,14 +514,14 @@ This restriction will be removed with the configuration parser improvement.
514514

515515
You can evaluate the Ruby code with `!fluent/s #{}` in `"` quoted string. This is useful for setting machine information e.g. hostname.
516516

517-
```text
517+
```yaml
518518
host_param: !fluent/s "#{Socket.gethostname}" # host_param is actual hostname like `webserver1`.
519519
env_param: !fluent/s "foo-#{ENV['FOO_BAR']}" # NOTE that foo-"#{ENV["FOO_BAR"]}" doesn't work.
520520
```
521521
522522
In YAML config format, `hostname` and `worker_id` shortcuts are also available:
523523

524-
```text
524+
```yaml
525525
host_param: !fluent/s "#{hostname}" # This is same with Socket.gethostname
526526
$id: !fluent/s "out_foo#{worker_id}" # This is same with ENV["SERVERENGINE_WORKER_ID"]
527527
```
@@ -530,22 +530,22 @@ The `worker_id` shortcut is useful under multiple workers. For example, for a se
530530

531531
Helper methods `use_nil` and `use_default` are available:
532532

533-
```text
533+
```yaml
534534
some_param: !fluent/s "#{ENV['FOOBAR'] || use_nil}" # Replace with nil if ENV["FOOBAR"] isn't set
535535
some_param: !fluent/s "#{ENV['FOOBAR'] || use_default}" # Replace with the default value if ENV["FOOBAR"] isn't set
536536
```
537537

538538
Note that these methods not only replace the embedded Ruby code but the entire string with `nil` or a default value.
539539

540-
```text
540+
```yaml
541541
some_path: !fluent/s "#{use_nil}/some/path" # some_path is nil, not "/some/path"
542542
```
543543

544544
### In double-quoted string literal, `\` is the escape character
545545

546546
The backslash `\` is interpreted as an escape character. You need `\` for setting `"`, `\r`, `\n`, `\t`, `\` or several characters in double-quoted string literal.
547547

548-
```text
548+
```yaml
549549
str_param: "foo\nbar" # \n is interpreted as actual LF character
550550
```
551551

0 commit comments

Comments
 (0)