TransWikia.com

Cleanup Craft Logs

Craft CMS Asked by judos on September 12, 2020

Whenever I have PHP problems I’m looking into the Craft CMS logs. However, at first I noticed there’s a ton of stuff getting logged which is useless for me. Under this amount of logs, I can’t find what I’m looking for so I want to get Craft CMS to stop logging parts.

Mainly the issue is that each and every POST, FILES, COOKIE, and SERVER variable present for any request is being logged. Which adds around 2 pages of text between the useful logging statements.

In the logs it looks as following:

2020-07-31 11:10:35 [-][-][-][info][DEV_migration_import_users] My useful message

$_POST = []

$_FILES = []

$_COOKIE = []

$_SERVER = [
    'HOSTNAME' => '...',
    'PHP_VERSION' => '7.2.32'
    'APACHE_CONFDIR' => '/etc/apache2'
    'PHP_MD5' => ''
    'PHP_INI_DIR' => '/usr/local/etc/php'
[AND ALL PASSWORDS, DB KEYS, SINGING ETC... at least 2 pages of text]

So I want to remove all these Variables from the logs. How can I do this?

I already tried to find the code where these Variables are logged and found vendor/yiisoft/yii2/base/ErrorHandler.php. But there are other things like "Previous exception:" which are not logged in my case. So this is not the correct code those Server variables are written (commenting out this confirmed it does not help).

PS. Related Problem but solved:

I had the same issue with every single SQL statement ever executed, was logged as well.
To remove these SQL statements I found this post: Is it possible to allow logging at LEVEL_INFO without logging all the SQL queries?

Which did help and reduce the huge amount of logs already quite a bit.

One Answer

As someone who theoretically might inherit your site one day... and also as future-you trying to diagnose a problem... please don't try to limit what Craft logs. If you want a quicker way to look for critical problems, check out the Yii2 Debug Toolbar as discussed here Profiling your Website with Craft CMS 3’s Debug Toolbar

You can use it to very quickly and easily see only errors, or only warnings, and so on. And then if the additional data that Craft logs is needed to help you diagnose a problem, it'll still be there.

To learn how to parse the Craft CMS log files quickly, check out the Zen and the Art of Craft CMS Log File Reading

If you do end up wanting to make your own logger, check out the Creating a Custom Logger for Craft CMS article

Answered by andrew.welch on September 12, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP