Drupal does logging via watchdog() and a module hook. That makes it only useful post-full-bootstrap when we have hooks.
Symfony, or at least the kernel, has a logging object (with interface) that it passes to many objects optionally. If things happen that need to get logged, it calls $logger->info() (and similar), which, because it's an interfaced object, can do whatever it wants behind the scenes. Right now we are not leveraging that anywhere.
We really ought to merge these. :-)
Option 1: Write a new logger class that internally wraps watchdog(). It takes whatever was called against the object and turns it into a watchdog() call. We then pass that object to wherever Symfony has one, and all is right with the world.
Option 2: Write a new logger class that does what we want, and make watchdog() a trivial wrapper of it. If we want it extensible then we can likely use a listener, as those should be available earlier than hooks. We can then transition over from watchdog() to logger objects (which we could even still call a watchdog object if we wanted to, for old time's sake) as stuff is refactored, and stick the logging object into the DIC so that everything is cleanly injected.
I personally prefer option 2, because it gets us further along toward an all-injected world and keeps watchdog() function calls out of objects; it's a hard-dependency to avoid. It's the more forward-thinking approach. That requires figuring out the registration of additional listeners, but we need to do that anyway.
Comments
Comment #1
fgmFWIW, I will be working on this: I already discussed it with amateescu a few days ago, and have some work on watchdog and its implementations, as well as using Monolog (outside Drupal/Symfony).
Comment #2
Crell commentedfgm: Spiffy. Are you looking at this from an approach 1 or approach 2 angle? And how does Monolog fit into the picture?
Comment #3
anavarreFYI, see also #1408208: Enable users to determine which types of log messages get written to dblog/syslog. Right now it's all or nothing.
Comment #4
fgmActually, I was thinking more along the lines of #2, except not specifically wanting to create a new Logger class from scratch, but using Monolog, which I like quite a lot, and already has a wrapper (bundle) in Symfony. Here is how I see it:
The main issue I'm worried about, at this point, is internationalization of watchdog messages, which currently relies on separate storing of messages class (the message column) and arguments, being merged by t(), whereas Monolog (for instance) does not provide this. The "extra" column which could store arguments only receives data from Processor classes, not from the Logger addRecord(). Of course, Monolog is only one option, The $context passed in all LoggerInterface can probably be used for this.
Another issue with Monolog would be the licensing, and I'm not sure what we would want to do about it: it is currently licensed by default under the "MIT" license (which version is not clear), not the GPL. Assuming this means the X.11 license, it is compatible with the GPLv2 or later, but this should be clarified with the author (Jordi Boggiano aka Seldaek). Not to be confused with the old similarly named Monolog library for Java by OW2, which was licensed under LGPL2.1.
Comment #5
fgm@anavarre: this is also related to one of my previous patches on that topic: #1268636: Watchdog should ignore reports below the system reporting level.
Comment #6
fgmYesterday at DrupalCamp Lyon, I did an impromptu presentation/discussion about the current watchdog() implementations, Symfony2 Logger interface, Monolog, and the envisioned implementation, what it brings us over the current situation (basically, it should be faster in many situations, and generally more useful), and discussed use scenarios for such an improved logging mechanism.
If you can make sense of them, @noisetteprod took a few shots of my whiteboard explanations: http://twitpic.com/9pxy8m http://twitpic.com/9pxyaj
Comment #7
Crell commentedI couldn't make heads or tails of the pictures, but yay for discussing things. :-) If I understand it, the plan in #4 seems sane. It sounds like implementing option 1 first, then migrating it to option 2 piecemeal. Is that correct? My main question is timing. Would we have development time to do that, or we end up caught part way through the migration when code freeze happens? That would suck. :-)
The MVP for me in this case is that any Symfony class that has a logger object parameter gets one, and we can do the same for any other object we spawn from the DIC. I'd want us to get to that ASAP.
MIT license is what Symfony2 uses, so is OK to include. Jordi is a Symfony dev as well.
Comment #8
catchThere's already an issue somewhere for porting watchdog to a class, along with some discussion of monolog. Let's please merge this one in either direction.
Comment #9
fgmWould that be #1289536: Switch Watchdog to a PSR-3 logging framework, or is there another one ? I hope to discuss a bit with jordi/seldaek at Symfony live next week, if he is available, since I've a pending pull request on Monolog too.
Comment #10
catchThat's the one yeah. I'm typing from phone so I won't try to mess with issue statuses, thanks for digging it out!
Comment #11
catchMarking this as duplicate of #1289536: Switch Watchdog to a PSR-3 logging framework, we can continue over there.
Comment #12
fgmFor the record, we had a discussion at Symfony Live with Crell and Seldaek, including my current D8 code and Monolog patches, of which I expect to have a first showable version during the Barcelona DevDays, as a basis for work.
Comment #13
fgmAlso, at DC Munich, @skottler mentioned existing code in the d.o. infra which probably needs to be considered too:
http://munich2012.drupal.org/program/sessions/turning-every-log-entry-go...