CodeIgniter Forums
Can't write a log message. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Can't write a log message. (/showthread.php?tid=82157)



Can't write a log message. - Eko - 06-18-2022

Hi, I try to write a log message like this:

   
PHP Code:
public function test()
    {
        log_message('error''Some variable was correctly set');
        echo 'test';
    

When I access that route I fine test message but I see no log. It doesn't over the threshold since I clear the log folder already. I can see an error log if my code got some error but not when I try to trigger using this code. Thanks.


RE: Can't write a log message. - includebeer - 06-18-2022

Make sure the writable folder is really writable and your log threshold is set to 4 or higher.
See https://codeigniter.com/user_guide/general/logging.html
and https://github.com/codeigniter4/CodeIgniter4/blob/develop/app/Config/Logger.php


RE: Can't write a log message. - Eko - 06-18-2022

I did already, I set it to 10 and it currently has 3 logs already, so I assume it's already writeable right? I'm really confused, I already read the docs and it said I just write log_message('error', 'Some variable was correctly set'); or did I miss something?


RE: Can't write a log message. - Eko - 06-19-2022

Never mind, when I take a look at common.php it said environment must be 'testing', I think you guys suppose to put that on documentation so a newcomer doesn't have to get into this trouble.


RE: Can't write a log message. - kenjis - 06-19-2022

(06-19-2022, 11:05 AM)Eko Wrote: Never mind, when I take a look at common.php it said environment must be 'testing', I think you guys suppose to put that on documentation so a newcomer doesn't have to get into this trouble.

What do you mean?

(06-18-2022, 07:21 AM)Eko Wrote: I did already, I set it to 10 and it currently has 3 logs already, so I assume it's already writeable right?

There is no `10`. The max number is `9`.
See https://github.com/codeigniter4/CodeIgniter4/blob/fe1dbc22003fb93d1b57addd3c35fe484cf5aedb/app/Config/Logger.php#L19-L30