Welcome Guest, Not a member yet? Register   Sign In
Newbie - can't get logging to work
#1

Hi all,

I've searched these forums and the broader internet for solutions, but I can't seem to get CodeIgniter logging to work. No log files are being created in the logs folder. I'm running CI 3.1.4 on Centos 7 and Apache. I loaded the CI framework to /var/www/CodeIgniter. I have a simple MVC app working fine except for logging. Here is an example log statement that I have, and it's in a code path that I know is getting executed:

log_message('debug', 'Loaded file');

I changed the permission of /var/www/CodeIgniter/application/logs to 777 just to try to get it working, but no luck.

In the config.php file, I have the following settings. I initially tried it with the default log_path (blank string) and then tried explicitly listing the log path as shown below. 


$config['log_threshold'] = 4;
$config['log_path'] = '/var/www/CodeIgniter/application/logs/';
$config['log_file_extension'] = '';
$config['log_file_permissions'] = 0644;

I don't see any errors in the Apache error log related to this. I've restarted Apache and even restarted my Centos VM. What am I missing?


Thanks
Reply
#2

That is peculiar. If you leave the 'log_path' blank (eg $config['log_path'] = ''; ) then the logs should be written into the standard logs directory under application. You only need to overwrite if you are changing the folder.

If you are doing this on a local host, I too have experienced weird affects where I just could not get the web server emulator to interpret certain commands correctly. IF you are on a local host, upload CI to a webhost and see if the log problem persists. At least then you know it is your XAMPP (or WAMP or whatever) causing the problem.

It might be your capital C in codeigniter causing an issue. I believe, but am not certain, that case sensitivity depends on the web server.
Reply
#3

Thanks Paul. I am running CI on a Centos VM and I'm accessing it from a browser on a different (Windows) machine. Is that what you were getting at when you asked whether I was using a localhost?

Might it have something to do with the fact that my application folder (/var/www/application) is above the root folder (/var/www/html)? My guess is no since that is a recommended configuration, but I figured that I'd ask. 

Also, does CI utilize Apache at all when writing to the log file? I'm just wondering if there is an Apache setting that I need to configure to get it to work.
Reply
#4

So I started digging into Logs.php in the core code and found the following regarding my setup:

$this->_log_path points (correctly) to /var/www/CodeIgniter/application/logs/
is_dir($this->_log_path) returns TRUE
is_really_writeable($this->_log_path) returns FALSE

The last item is causing the problem, i.e. CodeIgniter thinks that the logs folder isn't writable. But a listing of the application folder shows that it should be writable by everyone (777):

0 drwxr-xr-x. 14 root root 218 May 24 08:58 ./
0 drwxr-xr-x. 5 root root 173 May 31 11:15 ../
0 drwxr-xr-x. 2 root root 41 May 24 08:58 cache/
4 drwxr-xr-x. 2 root root 4096 May 31 16:24 config/
0 drwxr-xr-x. 3 root root 89 May 30 20:06 controllers/
0 drwxr-xr-x. 2 root root 24 May 24 08:58 core/
0 drwxr-xr-x. 2 root root 24 May 24 08:58 helpers/
0 drwxr-xr-x. 2 root root 24 May 24 08:58 hooks/
4 -rw-r--r--. 1 root root 123 May 24 08:58 .htaccess
4 -rw-r--r--. 1 root root 131 May 24 08:58 index.html
0 drwxr-xr-x. 3 root root 39 May 24 08:58 language/
0 drwxr-xr-x. 2 root root 24 May 24 08:58 libraries/
0 drwxrwxrwx. 2 root root 24 May 24 08:58 logs/
0 drwxr-xr-x. 2 root root 123 May 30 20:06 models/
0 drwxr-xr-x. 2 root root 24 May 24 08:58 third_party/
0 drwxr-xr-x. 5 root root 138 May 31 12:53 views/

Just on a lark, I tried changing the owner of everything in the CodeIgniter path to apache:apache, but it didn't make a difference.

So still no luck, but at least I know where the problem lies. Any suggestions would be welcome.

Thanks,
Dave
Reply
#5

(This post was last modified: 05-31-2017, 03:49 PM by DaveB.)

I finally solved it - it was an selinux issue. I've never really understood all the implications of selinux, so feel free to correct me if this is something dangerous to do from a security perspective, but I issued the following command in the application folder:

sudo chcon -R -t httpd_sys_rw_content_t logs

Once the logs were working, I found that I had to set my timezone in /etc/php.ini. Otherwise, the only log message that I got was that I needed to set my timezone...  Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB