mirror of
https://github.com/Seldaek/monolog.git
synced 2026-04-25 23:55:56 +03:00
[GH-ISSUE #55] writing to doctrine database #14
Labels
No labels
Bug
Documentation
Feature
Needs Work
Support
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/monolog#14
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kristofvc on GitHub (Feb 16, 2012).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/55
So I wrote a custom handler in symfony2:
In my config I defined this handler:
and I add it to the monolog:
I get the following error:
Think this is because doctrine tries to write to the log, and I use doctrine to safe a logitem, etc.
Is there a way around?
@Seldaek commented on GitHub (Feb 16, 2012):
Yes you should use the DBAL directly to avoid this recursive logging of a log of a log... So you can do something like:
You can also look at this for inspiration: https://github.com/Seldaek/monolog/blob/master/doc/extending.md
@kristofvc commented on GitHub (Feb 16, 2012):
I tried that already, same error.
Also tried to push a nullhandler to the logger before the persist and push, and pop it afterwards. But also, same error.
Any other suggestions?
@Seldaek commented on GitHub (Feb 16, 2012):
Oh right, executeQuery won't work since it logs. You can call getWrappedConnection() on the connection, and that will give you the raw PDO instance with which you can work.
The NullHandler should work IMO, but I guess I'm overlooking something that makes it fail..
@stof commented on GitHub (Feb 16, 2012):
you need to use a separate DBAL connection for which you disable the logging of queries
@Seldaek commented on GitHub (Feb 16, 2012):
Using the raw PDO object will work too.. no need to connect twice to the DB.
@damienalexandre commented on GitHub (May 28, 2012):
I'm trying to acheave what you have describe but I get a ServiceCircularReferenceException:
I think this is more a Symfony2 DIC related issue (as there is no Logger left in my doctrine.dbal.default.wrapped_connection, the Exception should not be thrown) but maybe this example can help.
The documentation miss a point: reusing an existing DBAL connection, and I think it's realy important.
Any idea on how we can solve (and then document all over the web) this issue?
@stof commented on GitHub (May 28, 2012):
there is a circular reference here: you need to create the
doctrine.dbal.default_connectionservice to create the doctrine.dbal.default.wrapped_connection`` (as it is used a factory service) and this service uses the logger.@stof commented on GitHub (May 28, 2012):
btw, I don't think you should use the same connection: it would put your logging queries inside the transactions, meaning you would loose them when the transaction is rollbacked (which is generally the case where you need your logs)
@ghost commented on GitHub (Aug 13, 2012):
I am getting circular reference error
Can someone please explain how to create as mentioned above
doctrine.dbal.default_connection service to create the doctrine.dbal.default.wrapped_connection``
@wimpog commented on GitHub (Sep 22, 2016):
Hello,
This is happening due to circular referencing caused by the $em->flush().
I have got this to work by adding the following code to only log messages coming from the 'app' channel. All others, including the ones caused by $em->flush() will be ignored.
Alternatively, you can add the channel name in the config.yml:
@bentcoder commented on GitHub (Nov 29, 2016):
Fully working example is here: http://www.inanzzz.com/index.php/post/53en/storing-symfony-log-messages-in-database-with-custom-monolog-handler
@wimpog commented on GitHub (Nov 30, 2016):
Great! Thank you! I've implemented it in a slightly different way,
filtering out anything but the 'app' channel, and also have log rotation.
Thanks!
On Tue, Nov 29, 2016 at 6:13 PM, BentCoder notifications@github.com wrote:
@seddighi78 commented on GitHub (Aug 31, 2019):
@BentCoder Thanks but not worked for Symfony 4.3.3
@bentcoder commented on GitHub (Aug 31, 2019):
Well, you are nearly 3 years late :)
@seddighi78 commented on GitHub (Aug 31, 2019):
oh! 😄 I found the solution thanks
@fabianoroberto commented on GitHub (Dec 11, 2019):
@seddighi78 how you solved?
@seddighi78 commented on GitHub (Dec 12, 2019):
By creating a new Logger file in
Logger/DatabaseLogger.phpwith this code:And then register to services: