70842[FEATURE] Add monolog as alternative logger implementation
Commit message
Review
-
Code review CR 0
-
Verified V 0
Issues 2
Files 22
- typo3/sysext/core/Classes/Core/BootService.php+2 −0
- typo3/sysext/core/Classes/Core/Bootstrap.php+18 −3
- typo3/sysext/core/Classes/DependencyInjection/LoggerAwarePass.php+2 −2
- typo3/sysext/core/Classes/DependencyInjection/LoggerInterfacePass.php+2 −2
- typo3/sysext/core/Classes/DependencyInjection/MonologLoggerPass.phpnew+96 −0
- typo3/sysext/core/Classes/Log/Handler/DatabaseHandler.phpnew+92 −0
- typo3/sysext/core/Classes/Log/Handler/DatabaseHandlerFactory.php2new+40 −0
- typo3/sysext/core/Classes/Log/Handler/HandlerFactoryInterface.phpnew+24 −0
- typo3/sysext/core/Classes/Log/Handler/HandlerFactoryRegistry.php4new+89 −0
- typo3/sysext/core/Classes/Log/Handler/StreamHandlerFactory.phpnew+113 −0
- typo3/sysext/core/Classes/Log/Processor/ComponentProcessor.phpnew+32 −0
- typo3/sysext/core/Classes/Log/Processor/RequestIdProcessor.phpnew+46 −0
- typo3/sysext/core/Classes/Log/LazyLogger.php2new+43 −0
- typo3/sysext/core/Classes/Log/LogManager.php6+80 −13
- typo3/sysext/core/Classes/ServiceProvider.php+29 −0
- typo3/sysext/core/Configuration/Services.php+1 −0
- typo3/sysext/core/Configuration/Services.yaml2+88 −0
- typo3/sysext/core/Documentation/Changelog/12.0/Feature-85506-AddMonologAsAlternativeLoggerImplementation.rstnew+117 −0
- typo3/sysext/core/composer.json2+1 −0
- typo3/sysext/core/ext_tables.sql+1 −1
Show 2 more files
Review log 2336
Show 611 earlier messages
-
Benjamin Franzke uploaded patch set 1 08/31/21, 14:50
-
core-ci voted on patch set 1 V -1 08/31/21, 15:15 Core CI is not happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/15943
-
Benjamin Franzke uploaded patch set 2 08/31/21, 15:33
-
core-ci voted on patch set 2 V +1 08/31/21, 15:53 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/15954
-
Benjamin Franzke uploaded patch set 3 08/31/21, 20:36
-
core-ci voted on patch set 3 V -1 08/31/21, 20:41 Core CI is not happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/15969
-
Benjamin Franzke uploaded patch set 4 08/31/21, 20:42
-
core-ci voted on patch set 4 V +1 08/31/21, 20:59 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/15971
-
Benjamin Franzke uploaded patch set 5 09/02/21, 00:07
-
core-ci voted on patch set 5 V -1 09/02/21, 00:25 Core CI is not happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/16041
-
Benjamin Franzke uploaded patch set 6 09/02/21, 01:04
-
core-ci voted on patch set 6 V +1 09/02/21, 01:26 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/16043
-
Benjamin Franzke uploaded patch set 7 09/02/21, 14:35
-
core-ci voted on patch set 7 V -1 09/02/21, 15:13 Core CI is not happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/16088
-
Benjamin Franzke uploaded patch set 8 09/02/21, 21:27
-
Benjamin Franzke uploaded patch set 9 09/02/21, 21:45
-
core-ci voted on patch set 8 V -1 09/02/21, 21:54 Core CI is not happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/16140
-
core-ci voted on patch set 9 V -1 09/02/21, 22:06 Core CI is not happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/16141
-
Benjamin Franzke uploaded patch set 10 09/03/21, 06:26
-
core-ci voted on patch set 10 V +1 09/03/21, 06:43 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/16153
-
crell commented on patch set 10 09/03/21, 17:41
HandlerFactoryRegistry.php:49$config['disabled'] ?? false is checked twice in just a few lines. It would be cleaner (for both this and channels) to keep it in the array and use ??= the first time to ensure it has a legit value. Viz, the line earlier changes to: $config['disabled'] ??= false; And then just use $config['disabled'] thereafter. Alternatively, since there's several of them, you can do it in a single operation: $config += [ 'disabled' => false, 'channels' => [], 'excluded_channels' => [], // ... ];LazyLogger.php:45This could also be inlined with ??= $logger = $this->logger ??= $this->logManager->getLoggerInstance($this->name);LogManager.php:76Shouldn't a Monolog-based LogManager be an alternate implementation of LogManagerInterface? The interface is there; this is exactly what alternate implementations are for.LoggerComponentClosure.php:21I... have no idea what this class is for, except that it is not a closure nor does it use one. So at minimum the name is bad. It needs a more descriptive name and likely a docblock to explain why it exists.DefaultConfiguration.php:1559I'm honestly not sure if the line formatter is appropriate for the DB handler or not. I had been planning to skip it and just use the raw data. Formatting should be done on display, not on storing into the DB.Services.yaml:430Is the intent to comment these out for committing, or remove them, or...? If they're left in then they're not really a demo.Feature-85506-AddMonologAsAlternativeLoggerImplementation.rst:20Period, not comma.Feature-85506-AddMonologAsAlternativeLoggerImplementation.rst:71Brackets missing, as this should be an array.Feature-85506-AddMonologAsAlternativeLoggerImplementation.rst:74It's not obvious to me if the attribute channel mechanism also works to create channels on the fly. It was already committed, but I'm not entirely clear if it works with this Monolog implementation. If it does, that should be included in this feature file for clarity.composer.json:41Why 2.0 and not 2.3? This will still get the 2.3 version of course but why not set the minimum at 2.3? -
Benni Mack commented on patch set 10 09/03/21, 20:36
Interesting approach, feels like a in-between mix of Symfony and TYPO3's current solution. Two things I wonder (and I want to experiment with): 1. Setting up the handlers / configuration of the handlers -> I think we should set up the handlers "on the fly", taking the configuration from TYPO3_CONF_VARS -> I dislike the autowiring magic, and I'm more in favor of how Laravel is just configuring it. 2. Having a solution (e.g. a trait) that allows our Logger to inherit from Monolog's Logger and first do Monologs logging solution (with an array), and then run TYPO3's processors and writers. What do you think about this approach? Never-the-less: Most important part is that our Writers should handle if it should be logged, not the Logger themselves as we do it right now. Maybe that would be something to be tackled as a pre-patch.DatabaseHandlerFactory.php:32I guess we'd need a Factory for all of Monolog's processors now, which have dependencies. Maybe that's the reason Symfony's Monolog Bridge is so massive. I'm not a fan of this...LogManager.php:76ReplyArgh, this is bad. We use Loggers in the Error Handler, which are registered before the DI container is built. this change seems like a bad work-around, I wonder if we could do the "switching" in the bootstrap, and use another LogManager. Or if we should re-set the ErrorHandlers after the DI container is done, and just hand in NullLoggers to the ErrorHandler until the DI container is available. I mean, that's a more general topic (out-of-scope here). don't know if we can resolve this -
Benjamin Franzke uploaded patch set 11 09/04/21, 15:24
-
Benjamin Franzke commented on patch set 11 09/04/21, 15:24
DatabaseHandlerFactory.php:32Reply UnresolvedTL;DR no, only for the common ones. Yea, well, therefore I've added the `monolog.handler` tag which allows to create *AND* configure a new handler via Services.yaml, without the need for a factory. my.whatever.I.name.it.stderr.handler: class: Monolog\Handler\StreamHandler arguments: $path: 'php://stderr' $level: 'debug' tags: - name: monolog.handler excluded_channels: foobar So we only need factories for the very basic handlers that need to be dynamically configurable via CONF_VARS.. @Benni: Fine by this?HandlerFactoryRegistry.php:30ReplySee .rst file for the reason/difference: The respective type needs to be implemented by a HandlerFactory. TYPO3 doesn't provide a factory for every monolog handler, as handlers can also be defined via dependency injection service definition Anyway, moved the $handlerServices out here (that was stupid to put it into handlerFACTORYregistry at all), as they can of course directly be wired in the compiler pass.HandlerFactoryRegistry.php:49ReplyAck, fixed, thank you.LazyLogger.php:45ReplyAck,done.LogManager.php:76Reply@Larry: sure, thought about it, but no chance: Throughout the core the `LogManager` is used *directly* throughout the core, and third party extensions do so as well. The LogManager is old, there were no DI, so noone used the interface as GeneralUtility::makeInstance couldn't resolve that.. …and I don't want to deprecate it and say please use "LogManagerInterface" instead, as I don't want anyone to use it directly, but to use dependency injection instead. Therefore we are bound to the "one" LogManager implementation. @Benni: This change isn't about the early bootstrap, it is in order to respect the feature toogle. This change already incorporates NullLogger for early bootstrap of error handlers and then injects new logger instances after container is setup (see Bootstrap.php).LoggerComponentClosure.php:21ReplyPreface: This is to support the legacy TYPO3 logging of the "component" (class). Yea well, a closure binds a function to it's scope – although in PHP you need to do this explicitly. So PHP closures are shit anyway and no real closures. But still, it is the intention of this class to be like a Closure, just for an object. This class binds the logger to the scope (=className/component), therefore I found this name to fit somehow. If one get's confused with real \Closure, well, then we should find a better name. I could also have used an anonymous class instead, then naming the class wouldn't have been a problem. I hope you agree, that an anonymous class is much like a Closure, but just for objects… I therefore simply switched to an anonymous class. Issue resolved ;)DefaultConfiguration.php:1559ReplyRight, thanks for bringing this up. The DatabaseHandler didn't use the formatted result at all, but already used the raw data. I've included this setting as AbstractProcessableHandlers default to using the LineFormatter if nothing is defined explicitly. Therefore I included it in this line to demonstrate this fact (should have put a comment in here). Of course, it made no sense in this case, as we don't use the result of the formatting. Conclusion: * I removed the needless formatter setting * I adapted the DatabaseHandler to not implement FormattableHandlerInterface at all, as it makes to sense to run a unused formatting here…Services.yaml:430ReplyYup, intent to remove. Did so right now (and rather moved into my local demo test extension)…Feature-85506-AddMonologAsAlternativeLoggerImplementation.rst:20ReplyAckFeature-85506-AddMonologAsAlternativeLoggerImplementation.rst:71ReplyArrays are not supported by symfony DI tags. Therefore, the channels string is exploded by comma into an array.Feature-85506-AddMonologAsAlternativeLoggerImplementation.rst:74ReplyIt doesn't autocreate channels – a channel needs to be defined explicitly. Yes, should be documented more clearly if this isn't clear enough. Maybe "have to be" or "MUST be" instead of "can be?" Changed to "have to be" for now.composer.json:41ReplyOh, well, I didn't care, rebased an old patch and didn't have a deeper look into the current version. I'm fine to incease the minimum requirement, and did so in the latest patchset. -
Benjamin Franzke uploaded patch set 12 09/04/21, 15:26
-
Benjamin Franzke uploaded patch set 13 09/04/21, 15:28
-
core-ci voted on patch set 13 V +1 09/04/21, 15:44 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/16259
-
crell commented on patch set 13 09/07/21, 15:29
Just some minor additional notes.LogManager.php:167This may well be the first use of an anonymous class I've seen outside of a test case setup. :-) (Congrats?)Feature-85506-AddMonologAsAlternativeLoggerImplementation.rst:24I think this is a grammar/translation issue. As written, this implies that the traditional framework is deprecated now, and will be undeprecated in 11.5. I don't think that's the intent. I think you mean "deprecated in 11.5 LTS", not "until." (Assuming that's the intent.) -
Benjamin Franzke commented on patch set 13 09/13/21, 15:57
LogManager.php:167Reply UnresolvedNo, look at or MiddlewareDispatcher, it uses an anonymous class as well, in order to bundle the stack-context into the PSR-15 request handler. And well, that's also authored by me, so I take the (likely ironical?) congratulations anyway…LogManager.php:179UnresolvedNote by Helmut Hummel: We should probably add a way to filter handlers by the TYPO3_COMPONENT context/extra data. Note by me: Could be implemented by a bubbling/non-bubbling (dependening on filter-state) Handler that is pushed above(before) other monolog handlers. => would be good to add such a ComponentFilterHandler(?) with and easy way to attach to channels or handlers (to be decided).Feature-85506-AddMonologAsAlternativeLoggerImplementation.rst:24Reply UnresolvedI meant "until [the release of] 11.5 LTS". I mean, I'm not a native english speaker, maybe that's still wrong grammar/usage of until… I think the sentence was pretty clear due to the introduction to say "it is likely that" ;) Anyway, now that the patch didn't end up in 11.4 that sentence would be removed anyway. Thanks for the heads up.Feature-85506-AddMonologAsAlternativeLoggerImplementation.rst:40UnresolvedRemark by Helmut Hummel: Example for configuration file location is missing. (Note: That is the key 'path') Should be included here. -
Benni Mack wrote 11/29/21, 10:09
Change destination moved from master to main -
Benni Mack updated the commit message in patch set 14 11/29/21, 13:27
-
core-ci voted on patch set 14 V +1 11/29/21, 14:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/20032
-
Benni Mack uploaded patch set 15 12/18/21, 07:46
-
core-ci voted on patch set 15 V -1 12/18/21, 07:57 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/21229
-
Christian Kuhn commented on patch set 15 06/11/23, 22:58
hey. the logging topic seems to be stuck for quite a while (again). This patch stalled and it looks as if nobody is taking care of it at the moment. I'll abandon here for now. We could pick up later in case this gains traction again. -
Christian Kuhn abandoned the change 06/11/23, 22:58
HandlerFactoryRegistry.php:30