nette / tracy

😎 Tracy: the addictive tool to ease debugging PHP code for cool developers. Friendly design, logging, profiler, advanced features like debugging AJAX calls or CLI support. You will love it.
https://tracy.nette.org
Other
1.75k stars 218 forks source link

TracyExtension: set mailer to logger service instead of staticly get logger #551

Closed mabar closed 1 year ago

mabar commented 1 year ago

Commit https://github.com/nette/tracy/commit/0b615627e1229d33abc016620c8239ebcb20654f introduces condition that breaks my logger. It connects Monolog and Tracy logger in a way it is possible to log from Tracy to Monolog and from Monolog to Tracy while maintaining configuration of these loggers.

Since condition was introduced, replacing Tracy\Logger causes mailer option to be ignored if Monolog extension is loaded firsts. Because at point where mailer is set, Tracy\Debugger::getLogger() already returns different instance.

broken

By changing Tracy\Debugger::getLogger() to $this->getService('tracy.logger') I can maintain logger compatibility, while keeping fix for #549.

fixed

Note: These options probably have the same problem as described in #549. https://github.com/nette/tracy/blob/0b615627e1229d33abc016620c8239ebcb20654f/src/Bridges/Nette/TracyExtension.php#L104-L105

If we change these calls from static getLogger() to getService() we may as well check if service tracy.logger will create Tracy\Logger and if not and one of these options is set, warn user about incompatible logger. Because current condition fix is just ignoring incompatible options which should not be set, if logger does not support them.

Sorry for long description, it was just crazy complex to make loggers work perfectly fine together and I don't have any other way of fixing it.

dg commented 1 year ago

I tried to solve it like this: 0d551ba7cafec4548ff5617bf358e3ece767cecc

It's just a hack for the patch version for now. In the next major release we'd fix it better.

mabar commented 1 year ago

One more workaround on my side, but it seems to be working fine, thanks https://github.com/orisai/nette-monolog/pull/3/files#diff-34f516dc85e79726f910d1b0e989ea939cbf310611cf0507e69eee3b4a12a127

dg commented 1 year ago

I must have misunderstood... So they'll use your PR instead.

dg commented 1 year ago

Is this dea9aa33fd2ab91e3123d90d83cffe00feb62f72 good for you?

mabar commented 1 year ago

Yes, that works without any workarounds, thanks.