Skip to content

Commit 2040a54

Browse files
committed
provided usage description
1 parent 00e2af7 commit 2040a54

File tree

3 files changed

+38
-19
lines changed

3 files changed

+38
-19
lines changed

README.md

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,28 @@
33
Transform your application logs to structured logs that comply with the [Elastic Common Schema (ECS)](https://www.elastic.co/guide/en/ecs/current/ecs-reference.html).
44
In combination with [filebeat](https://www.elastic.co/products/beats/filebeat) you can send your logs directly to Elasticsearch and leverage [Kibana's Logs UI](https://www.elastic.co/guide/en/infrastructure/guide/current/logs-ui-overview.html) to inspect all logs in one single place.
55
This library allows you to provide more observability for your PHP applications as can e.g. corrolate your logs with e.g. APM traces.
6+
See [ecs-logging](https://github.com/elastic/ecs-logging) for other ECS logging libraries and more resources about ECS & logging.
67

7-
## Usage
8-
9-
Please note that the major version of this library is compatible with the major version of ECS.
10-
11-
### Install
12-
8+
## Install
139
```
1410
composer require elastic/ecs-logging-php
1511
```
1612

17-
### Monolog Formater
18-
```php
19-
use Monolog\Logger;
20-
use Monolog\Handler\StreamHandler;
21-
use Elastic\Monolog\Formatter\ElasticCommonSchemaFormatter;
22-
23-
$logger = new Logger('my_ecs_logger');
24-
$formatter = new ElasticCommonSchemaFormatter();
25-
$handler = new StreamHandler('<path-to-log-dir>/application.json', Logger::INFO);
26-
$handler->setFormatter($formatter);
27-
$logger->pushHandler($handler);
28-
```
13+
## Examples and Usage
14+
* [Monolog](https://github.com/elastic/ecs-logging-php/blob/master/docs/Monolog/README.md)
2915

3016
## Library Support
31-
Currently only [Monolog:2.*](https://github.com/Seldaek/monolog) is supported.
17+
* Currently only [Monolog:2.*](https://github.com/Seldaek/monolog) is supported.
18+
* The major version of this library is compatible with the major version of ECS.
3219

3320
## References
3421
* Introduction to ECS [blog post](https://www.elastic.co/blog/introducing-the-elastic-common-schema).
3522
* Logs UI [blog post](https://www.elastic.co/blog/infrastructure-and-logs-ui-new-ways-for-ops-to-interact-with-elasticsearch).
3623

24+
## Test
25+
```
26+
composer test
27+
```
28+
3729
## License
3830
This software is licensed under the [Apache 2 license](https://github.com/elastic/ecs-logging-php/blob/master/LICENSE).

docs/Monolog/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Monolog
2+
3+
## Initialize the Formatter
4+
```php
5+
use Monolog\Logger;
6+
use Monolog\Handler\StreamHandler;
7+
use Elastic\Monolog\Formatter\ElasticCommonSchemaFormatter;
8+
9+
$logger = new Logger('my_ecs_logger');
10+
$formatter = new ElasticCommonSchemaFormatter();
11+
$handler = new StreamHandler('<path-to-log-dir>/application.json', Logger::INFO);
12+
$handler->setFormatter($formatter);
13+
$logger->pushHandler($handler);
14+
```
15+
16+
## Log Throwable's
17+
In order to enrich your error log message with [`Throwable`](https://www.php.net/manual/en/class.throwable.php)'s data, you need to pass
18+
the _caught_ exception or error with the key `throwable` in the context of the log message.
19+
```php
20+
$logger->error($t->getMessage(), ['throwable' => $t]);
21+
```
22+
23+
## Trace Context
24+
You can add a trace context to every log message by leveraging the `trace` key in contex to pass a trace Id.
25+
```php
26+
$logger->notice('I am a log message with a trace id, so you can do awesome things in the Logs UI', ['trace' => $traceId]);
27+
```

docs/assets/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)