Closed seb-enovate closed 3 months ago
@seb-enovate Since Craft 4, when Craft started using Monolog for its logging, the default minimum level was changed to info
when dev mode is enabled. You're right that in Craft 3, it was trace
, aka debug
.
To print Craft::debug()
logs, you can change the default logging level in config/app.php
like so:
<?php
use Psr\Log\LogLevel;
return [
'components' => [
'log' => [
'monologTargetConfig' => [
'level' => LogLevel::DEBUG,
],
],
],
];
Alternatively, if this is for a dedicated module/plugin, you can set up a dedicated log target with whatever level you specify. Examples of both of these configurations can be found in the docs.
Thanks Tim. I'm just wondering if the docs ought to be tweaked slightly. For example in this section of the docs:
It states the convenience methods, which includes trace
and debug
, and then says:
By default, Craft logs all levels when devMode is enabled. Otherwise, anything lower than warning will be ignored.
To me, "Craft logs all levels" suggests that trace
and debug
would work, even though as you've explained this is intentionally not the case?
Indeed, that is misleading, and likely leftover from when that was the case. We'll get it updated!: https://github.com/craftcms/docs/pull/639
What happened?
Description
We have an internal plugin that we use for many of our Craft CMS projects. It uses
Craft::debug()
to write debug logs in the dev environment. However, I've noticed that this no longer works in projects running Craft 4 or later.Steps to reproduce
php craft make module
command to setup a test moduleCraft::debug()
line to theinit()
method of the moduletail -f storage/logs/* | grep 'web.DEBUG'
to watch the logs in the terminaldebug
log entry is writtenExpected behavior
debug
entries are written to the log.Actual behavior
No
debug
entries are written to the log.Craft CMS version
4+
PHP version
No response
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
No response