diff --git a/README.md b/README.md index 7fcbcc2..081e261 100644 --- a/README.md +++ b/README.md @@ -10,115 +10,9 @@ See [ecs-logging](https://github.com/elastic/ecs-logging) for other ECS logging **Please note** that this library is in a pre-1.0 version and backwards-incompatible changes might be introduced in future releases. While we strive to comply to [semver](https://semver.org/), we can not guarantee to avoid breaking changes in minor releases. -## Installation +## Documentation -Add this line to your application's Gemfile: - -```ruby -gem 'ecs-logging' -``` - -And then execute: - - $ bundle install - -Or install it yourself as: - - $ gem install ecs-logging - -## Usage - -`Ecs::Logger` is a subclass of Ruby's own [`Logger`](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html) and responds to the same methods. - -```ruby -require 'ecs/logger' - -logger = Ecs::Logger.new($stdout) -logger.info('my informative message') -logger.warn { 'be aware that…' } -logger.error('a_progname') { 'oh no!' } -``` - -Logs the following JSON to `$stdout`: - -```ndjson - {"@timestamp":"2020-11-24T13:32:21.329Z","log.level":"INFO","message":"very informative","ecs.version":"1.4.0"} - {"@timestamp":"2020-11-24T13:32:21.330Z","log.level":"WARN","message":"be aware that…","ecs.version":"1.4.0"} - {"@timestamp":"2020-11-24T13:32:21.331Z","log.level":"ERROR","message":"oh no!","ecs.version":"1.4.0","process.title":"a_progname"} -``` - -Additionally, it allows for adding additional keys to messages, eg: - -```ruby -logger.info('ok', labels: { my_label: 'value' }, 'trace.id': 'abc-xyz') -``` - -Logs: - -```json -{ - "@timestamp":"2020-11-24T13:32:21.331Z", - "log.level":"ERROR", - "message":"oh no!", - "ecs.version":"1.4.0", - "labels":{"my_label":"value"}, - "trace.id":"abc-xyz" -} -``` - -To include info about where the log was called, call the methods with `include_origin: true`, like: - -```ruby -logger.warn('Hello!', include_origin: true) -``` - -Resulting in - -```json -{ - "@timestamp":"2020-11-24T13:32:21.331Z", - "log.level":"WARN", - "message":"Hello!", - "ecs.version":"1.4.0", - "log.origin": { - "file.line": 123, - "file.name": "my_file.rb", - "function": "call" - } -} -``` - -## Usage with Rack - -```ruby -use EcsLogging::Middleware, $stdout -``` - -Example output: - -```json -{ - "@timestamp":"2020-12-07T13:44:04.568Z", - "log.level":"INFO", - "message":"GET /", - "ecs.version":"1.4.0", - "client":{ - "address":"127.0.0.1" - }, - "http":{ - "request":{ - "method":"GET", - "body.bytes":"0" - } - }, - "url":{ - "domain":"example.org", - "path":"/", - "port":"80", - "scheme":"http" - } -} -``` +Ready to get started? Documentation is at [elastic.co](https://www.elastic.co/guide/en/ecs-logging/ruby/current/index.html). ## License