Welcome Guest, Not a member yet? Register   Sign In
Changing Log threshold at runtime


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:
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 ?

The bootstrap loads the logger before you are setting the log threshold.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

You may consider setting log thresholds in an env variable.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!

Theme © iAndrew 2016 - Forum software by © MyBB