12

I can't seem to figure out why codeigniter isn't logging my log_messages

In Config:

$config['log_threshold'] = 4;
$config['log_path'] = '/var/log/mydlp.log';

In script:

log_message('error','here');

File location:

-rw-rw-rw- 1 root  root    0 2012-12-05 13:10 mydlp.log

I'm not getting anything when I get to the log message.

Here's my directory structure for /var and /var/log

 drwxr-xr-x  6 root root  4096 2012-12-05 13:10 log
 drwxr-xr-x  14 root root  4096 2012-01-04 14:38 var

Am I doing something wrong here?

Aram Papazian
  • 2,453
  • 6
  • 38
  • 45

2 Answers2

15

$config['log_path'] is supposed to be a path to a directory, not a file. CI writes its own files in the format log-2012-12-05.php. Try a path to a directory, and make sure to include a trailing slash.

/*
|--------------------------------------------------------------------------
| Error Logging Directory Path
|--------------------------------------------------------------------------
|
| Leave this BLANK unless you would like to set something other than the default
| application/logs/ folder. Use a full server path with trailing slash.
|
*/
$config['log_path'] = '/var/log/ci_logs/';
Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
  • Is 755 ok for the permissions or does it need to be 777? – Aram Papazian Dec 05 '12 at 18:28
  • 3
    looks like 755 didn't work, I had to switch it to 777, but I'm assuming that's cause the folder was created by root. I'll change it to the server then it should work 755. Thanks tons. – Aram Papazian Dec 05 '12 at 18:32
  • 2
    Yeah I think I had to do the same and just used 777. – Wesley Murch Dec 05 '12 at 18:33
  • 3
    +1 also had to use 777 remotely but 755 worked locally. I believe it's a user group issue where my remote server has a different apache user than that of the directory owner. – grant Apr 27 '15 at 13:40
  • 2
    Previously wondering why it works locally but not in the server, so I tried 777 file permission and it works in remote server. – Eddy Goh Apr 26 '18 at 04:09
  • Make sure the log_path is a full path. – Wilson Feb 19 '20 at 02:00
  • Make sure the log_path is a full path and writable. E.g. C:\wamp64\www\your_project\application\logs/. This worked for me – Wilson Feb 19 '20 at 02:01
3

the problem is SELinux check this post.

you try this:

# Ownership
sudo chown apache:apache -R /data/www/html/sites/mysite
cd /data/www/html/sites/mysite

# File permissions, recursive
find . -type f -exec chmod 0644 {} \;

# Dir permissions, recursive
find . -type d -exec chmod 0755 {} \;

# SELinux serve files off Apache, resursive
sudo chcon -t httpd_sys_content_t /data/www/html/sites/mysite -R

# Allow write only to specific dirs
sudo chcon -t httpd_sys_rw_content_t /data/www/html/sites/mysite/logs -R
sudo chcon -t httpd_sys_rw_content_t /data/www/html/sites/mysite/uploads -R

https://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/