CodeIgniter Forums
Changing Log threshold at runtime - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: Changing Log threshold at runtime (/showthread.php?tid=75451)



Changing Log threshold at runtime - Mobostar - 02-07-2020

Hi,

I have started getting myself used to CI4 recently. I was reading the manual and I wanted to try and see how I can modify Log threshold setting at runtime.

So, I put the following code into index.php after the line that loads the bootstrap.php.

PHP Code:
config('Config\\Logger')->threshold 5

Then I did a print_r('Config\\Logger') in my view file to see the Log settings and I got the following:
Code:
Config\Logger Object
(
    [threshold] => 5
    [path] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
    [dateFormat] => Y-m-d H:i:s
    [handlers] => Array
        (
            [CodeIgniter\Log\Handlers\FileHandler] => Array
                (
                    [handles] => Array
                        (
                            [0] => critical
                            [1] => alert
                            [2] => emergency
                            [3] => debug
                            [4] => error
                            [5] => info
                            [6] => notice
                            [7] => warning
                        )

                    [path] => /var/www/local.ci4.com/writable/logs/
                    [fileExtension] => php
                    [filePermissions] => 420
                )

        )

)

So far so good. The new threshold value is set (default threshold value in app/Config/Logger.php is 3).

Threshold 5 allows 'error' messages, but the default threshold 3 does not. So, I try log_message('error', 'Some error happened!') to test it, but it does not work. The error message does not go into the log file.

If I set the threshold to 5 in the app/Config/Logger.php then the same test works.

I am using CI4.rc3 installed via Composer.

What am I missing ?


RE: Changing Log threshold at runtime - InsiteFX - 02-08-2020

The bootstrap loads the logger before you are setting the log threshold.


RE: Changing Log threshold at runtime - albertleao - 02-08-2020

You may consider setting log thresholds in an env variable.