Skip to content

Commit 9b138b9

Browse files
[docs] Migrate docs from AsciiDoc to Markdown (#79)
* delete asciidoc files * add migrated files
1 parent 43e67d5 commit 9b138b9

File tree

7 files changed

+676
-105
lines changed

7 files changed

+676
-105
lines changed

docs/docset.yml

Lines changed: 488 additions & 0 deletions
Large diffs are not rendered by default.

docs/index.asciidoc

Lines changed: 0 additions & 16 deletions
This file was deleted.

docs/intro.asciidoc

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/reference/index.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/ecs-logging/php/current/intro.html
4+
- https://www.elastic.co/guide/en/ecs-logging/php/current/index.html
5+
---
6+
7+
# ECS Logging PHP [intro]
8+
9+
ECS loggers are formatter/encoder plugins for your favorite logging libraries. They make it easy to format your logs into ECS-compatible JSON.
10+
11+
::::{tip}
12+
Want to learn more about ECS, ECS logging, and other available language plugins? See the [ECS logging guide](ecs-logging://docs/reference/intro.md).
13+
::::
14+
15+
16+
Ready to jump into `ecs-logging-php`? [Get started](/reference/setup.md).
17+

docs/reference/setup.md

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/ecs-logging/php/current/setup.html
4+
navigation_title: Get started
5+
---
6+
7+
# Get started with ECS Logging PHP [setup]
8+
9+
::::{note}
10+
ECS logging for PHP is currently only available for Monolog v2.*.
11+
::::
12+
13+
14+
15+
## Step 1: Set up application logging [setup-step-1]
16+
17+
18+
### Add the dependency [_add_the_dependency]
19+
20+
```cmd
21+
composer require elastic/ecs-logging
22+
```
23+
24+
25+
### Configure monolog logger [_configure_monolog_logger]
26+
27+
`Elastic\Monolog\v2\Formatter\ElasticCommonSchemaFormatter` implements Monolog’s [`FormatterInterface`](https://github.com/Seldaek/monolog/blob/2.0.0/src/Monolog/Formatter/FormatterInterface.php) and thus it can be used when setting up Monolog logger.
28+
29+
For example:
30+
31+
```php
32+
use Monolog\Logger;
33+
use Monolog\Handler\StreamHandler;
34+
use Elastic\Monolog\Formatter\ElasticCommonSchemaFormatter;
35+
36+
$log = new Logger('MyLogger');
37+
$handler = new StreamHandler('php://stdout', Logger::DEBUG);
38+
$handler->setFormatter(new ElasticCommonSchemaFormatter());
39+
$log->pushHandler($handler);
40+
41+
$log->warning('Be aware that...');
42+
```
43+
44+
Logs the following JSON to standard output:
45+
46+
```json
47+
{"@timestamp":"2021-02-07T18:08:07.229676Z","log.level":"WARNING","message":"Be aware that...","ecs.version":"1.2.0","log":{"logger":"MyLogger"}}
48+
```
49+
50+
Additionally, it allows for adding additional keys to messages.
51+
52+
For example:
53+
54+
```php
55+
$log->info('My message', ['labels' => ['my_label_key' => 'my_label_value'], 'trace.id' => 'abc-xyz']);
56+
```
57+
58+
Logs the following (multi-line formatted for better readability):
59+
60+
```json
61+
{
62+
"@timestamp": "2021-02-08T06:36:38.913824Z",
63+
"log.level": "INFO",
64+
"message": "My message",
65+
"ecs.version": "1.2.0",
66+
"log": {
67+
"logger": "MyLogger"
68+
},
69+
"labels": {
70+
"my_label_key": "my_label_value"
71+
},
72+
"trace.id": "abc-xyz"
73+
}
74+
```
75+
76+
77+
## Step 2: Configure Filebeat [setup-step-2]
78+
79+
:::::::{tab-set}
80+
81+
::::::{tab-item} Log file
82+
1. Follow the [Filebeat quick start](beats://docs/reference/filebeat/filebeat-installation-configuration.md)
83+
2. Add the following configuration to your `filebeat.yaml` file.
84+
85+
For Filebeat 7.16+
86+
87+
```yaml
88+
filebeat.inputs:
89+
- type: filestream <1>
90+
paths: /path/to/logs.json
91+
parsers:
92+
- ndjson:
93+
overwrite_keys: true <2>
94+
add_error_key: true <3>
95+
expand_keys: true <4>
96+
97+
processors: <5>
98+
- add_host_metadata: ~
99+
- add_cloud_metadata: ~
100+
- add_docker_metadata: ~
101+
- add_kubernetes_metadata: ~
102+
```
103+
104+
1. Use the filestream input to read lines from active log files.
105+
2. Values from the decoded JSON object overwrite the fields that {{filebeat}} normally adds (type, source, offset, etc.) in case of conflicts.
106+
3. {{filebeat}} adds an "error.message" and "error.type: json" key in case of JSON unmarshalling errors.
107+
4. {{filebeat}} will recursively de-dot keys in the decoded JSON, and expand them into a hierarchical object structure.
108+
5. Processors enhance your data. See [processors](beats://docs/reference/filebeat/filtering-enhancing-data.md) to learn more.
109+
110+
111+
For Filebeat < 7.16
112+
113+
```yaml
114+
filebeat.inputs:
115+
- type: log
116+
paths: /path/to/logs.json
117+
json.keys_under_root: true
118+
json.overwrite_keys: true
119+
json.add_error_key: true
120+
json.expand_keys: true
121+
122+
processors:
123+
- add_host_metadata: ~
124+
- add_cloud_metadata: ~
125+
- add_docker_metadata: ~
126+
- add_kubernetes_metadata: ~
127+
```
128+
::::::
129+
130+
::::::{tab-item} Kubernetes
131+
1. Make sure your application logs to stdout/stderr.
132+
2. Follow the [Run Filebeat on Kubernetes](beats://docs/reference/filebeat/running-on-kubernetes.md) guide.
133+
3. Enable [hints-based autodiscover](beats://docs/reference/filebeat/configuration-autodiscover-hints.md) (uncomment the corresponding section in `filebeat-kubernetes.yaml`).
134+
4. Add these annotations to your pods that log using ECS loggers. This will make sure the logs are parsed appropriately.
135+
136+
```yaml
137+
annotations:
138+
co.elastic.logs/json.overwrite_keys: true <1>
139+
co.elastic.logs/json.add_error_key: true <2>
140+
co.elastic.logs/json.expand_keys: true <3>
141+
```
142+
143+
1. Values from the decoded JSON object overwrite the fields that {{filebeat}} normally adds (type, source, offset, etc.) in case of conflicts.
144+
2. {{filebeat}} adds an "error.message" and "error.type: json" key in case of JSON unmarshalling errors.
145+
3. {{filebeat}} will recursively de-dot keys in the decoded JSON, and expand them into a hierarchical object structure.
146+
::::::
147+
148+
::::::{tab-item} Docker
149+
1. Make sure your application logs to stdout/stderr.
150+
2. Follow the [Run Filebeat on Docker](beats://docs/reference/filebeat/running-on-docker.md) guide.
151+
3. Enable [hints-based autodiscover](beats://docs/reference/filebeat/configuration-autodiscover-hints.md).
152+
4. Add these labels to your containers that log using ECS loggers. This will make sure the logs are parsed appropriately.
153+
154+
```yaml
155+
labels:
156+
co.elastic.logs/json.overwrite_keys: true <1>
157+
co.elastic.logs/json.add_error_key: true <2>
158+
co.elastic.logs/json.expand_keys: true <3>
159+
```
160+
161+
1. Values from the decoded JSON object overwrite the fields that {{filebeat}} normally adds (type, source, offset, etc.) in case of conflicts.
162+
2. {{filebeat}} adds an "error.message" and "error.type: json" key in case of JSON unmarshalling errors.
163+
3. {{filebeat}} will recursively de-dot keys in the decoded JSON, and expand them into a hierarchical object structure.
164+
::::::
165+
166+
:::::::
167+
For more information, see the [Filebeat reference](beats://docs/reference/filebeat/configuring-howto-filebeat.md).
168+

docs/reference/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
toc:
2+
- file: index.md
3+
- file: setup.md

docs/setup.asciidoc

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)