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

DI: handlers are global #2

Open
mkoubik opened this issue Sep 23, 2014 · 3 comments
Open

DI: handlers are global #2

mkoubik opened this issue Sep 23, 2014 · 3 comments

Comments

@mkoubik
Copy link

mkoubik commented Sep 23, 2014

TLDR: Is there any support for multiple channels in a single extension?

I want to log SQL queries separately besides logging exceptions (ideally to have another instance of Monolog\Logger) so I tried to register multiple MonologExtensions like this:

extensions:
    monolog.errors: Kdyby\Monolog\DI\MonologExtension
    monolog.sql: Kdyby\Monolog\DI\MonologExtension

monolog.errors:
    name: errors

monolog.sql:
    name: sql
    registerFallback: no
    hookToTracy: no
    handlers:
        ...

The problem is that handlers from monolog.sql have "global" tag monolog.handler so monolog.errors uses them as well. Instead I would like the tag prefixed (monolog.sql.handler) so you can register the extension multiple times.
Is this a valid solution, should I send PR (it's a BC break)?

@fprochazka
Copy link
Member

Interesting solution. But I would preffer having structured configuration of a single extension. Like in Kdyby/Doctrine.

monolog:
    errors:
        name: errors
        handlers: ...

    sql:
        registerFallback: no
        hookToTracy: no
        handlers: ...

but then, the problem with tags remains...


I think one tag should remain, but when it has a metadata (tags can have additional meta) then register only to the monolog named as the metadata of the handler tag

services:
    - {class: ..., tags: [monolog.handler]} # this will be registered to all Logger instances
    - {class: ..., tags: [monolog.handler: errors]} # only to instance named "errors"
    - {class: ..., tags: [monolog.handler: sql]} # only to instance named "sql"

@ldrahnik
Copy link

Is there any workaround to do that? will be solved? i agree with @mkoubik

@fprochazka
Copy link
Member

There is currently no workaround I'm aware of.

I'm working a bit with symfony now, so I intent to copy their style of configuring monolog, since this lib has very weak support for complex channel+handler setups.

enumag pushed a commit that referenced this issue Jul 21, 2019
Minor fixes & increase code coverage for PR to Kdyby/Monolog for Nette v 3.0
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

No branches or pull requests

3 participants