Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional dispatch #9

Merged
merged 3 commits into from
Nov 7, 2022
Merged

Conditional dispatch #9

merged 3 commits into from
Nov 7, 2022

Conversation

solnic
Copy link
Member

@solnic solnic commented Nov 7, 2022

You can now configure log_if on a per-backend basis. This is a simple
function that receives a log entry object and it's meant to return
either true or false.

You can use it like that:

logger = Dry.Logger(:test)
  .add_backend(formatter: :string) { |backend|
    backend.log_if = -> entry { entry.info? }
  }.
  .add_backend(formatter: :string) { |backend|
    backend.log_if = -> entry { entry.error? }
  }

In this case the first backend will be used only for info logs, and the
second one will be used only for error logs.

@solnic solnic force-pushed the conditional-dispatch branch 2 times, most recently from 6c3bf93 to b492fee Compare November 7, 2022 10:09
You can now configure `log_if` on a per-backend basis. This is a simple
function that receives a log entry object and it's meant to return
either true or false.

You can use it like that:

```ruby
logger = Dry.Logger(:test)
  .add_backend(formatter: :string) { |backend|
    backend.log_if = -> entry { entry.info? }
  }.
  .add_backend(formatter: :string) { |backend|
    backend.log_if = -> entry { entry.error? }
  }
```

In this case the first backend will be used only for info logs, and the
second one will be used only for error logs.
@solnic solnic marked this pull request as ready for review November 7, 2022 10:28
@solnic solnic merged commit 6005df2 into main Nov 7, 2022
@solnic solnic deleted the conditional-dispatch branch November 7, 2022 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant