2

I have a Codeigniter application, in which I am logging the error, debug and info messages. In config.php, I have set the threshold value as 4. I could see the log file in application/log folder. Now I tried to add a custom log from a method from a controller. I used

log_message("error", "this is my custom error");

But this is not logging in the log file. What I tried so far

  • Changed the log file location
  • Changed the log file permission
  • Changed the level with 'debug', 'info'.
  • Applied the changes in server files to see if it works in another server.

Nothing writing the log. In the existing log file, I can see the log messages from core files. I cannot write anything from the application folder.

2 Answers2

6

For debugging update config.php as follows

$config['log_threshold'] = 4;
$config['log_path'] = '';
$config['log_file_extension'] = '';
$config['log_file_permissions'] = 0775;

In command line go to your 'application' folder using cd command

Try these commands

  1. sudo chgrp -R www-data logs/
  2. sudo chmod -R 775 logs/

Check log using controller.

Mohammedshafeek C S
  • 1,916
  • 2
  • 16
  • 26
1
  1. Ensure your CI application/logs file has write permission by the web user.

  2. Here are the relevant snippets from your application/config/config.php file:

    $config['log_threshold'] = 4; $config['log_path'] = '';

  3. Restart your web server (e.g. "/etc/init.d/apache2 stop/start" for many versions of Linux.

...

  1. if you're absolutely certain your log_message() is getting called, and you still don't see any entries in "application/logs", then consider changing log_path to a different path (e.g. /tmp, if only for troubleshooting purposes).

  2. However, even "/tmp" isn't a Sure Thing. Look at my post on how Systemd redirects PHP/Apache to a "private temp":

    Why doesn't PHP 7.2 fopen(/tmp, a) write to the file?

  3. Failing all else, the problem might be SELinux:

    CentOS 7 + SELinux + PHP + Apache – cannot write/access file no matter what

Good luck - and please post back what you find!

Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • Thanks for your answer. Please find my comments on each point – Muhammed Shihabudeen Labba A Sep 30 '19 at 06:34
  • Thanks for your answer. Please find my comments on each point 1) Logfile has write permission and it is writing. In my application I have log_message() called from core files. It is writing in log file. 2) Correct 3) Restarted apache. 4) Actually, the log file is writing, but my concern is, when I add log_message() in my controller method, it is not writing. Still I changed the path. 5) 6) I am using Ubuntu 18.04 with Apache – Muhammed Shihabudeen Labba A Sep 30 '19 at 06:45