Reputation: 51
I want to use log_message in Codeigniter but log_message does not write anything in the log file.
$config['log_threshold'] = 4;
$config['log_path'] = 'http://spsvn01/var/www/html/RAIDLOG/application/logs/';
And in my controller I write :
log_message('error','USER_INFO '.$user_info['email']);
Thanks a lot !
Upvotes: 2
Views: 41773
Reputation: 1
It's an old post but can help someone: My codeigniter log has not be written, so I go to logs folder and execute this command: sudo chown www-data logs/
Turn user www-data owner of the folder and then its work.
Upvotes: 0
Reputation:
I would use the FCPATH
constant which points to your application folder:
$config['log_threshold'] = 4;
$config['log_path'] = FCPATH . '/application/logs/';
Works fine on my end.
http://www.codeigniter.com/user_guide/general/errors.html
Informational Messages
log_message('info', 'USER_INFO ' . $user_info['email']);
Error Messages
log_message('error', 'USER_INFO ' . $user_info['email']);
Also, the logs folder must be writable. Do a CHMOD 700
on the folder.
Upvotes: 7
Reputation: 233
open the your_project_dir/application/config/config.php
In config file you'll find 3 default variables
$config['log_threshold']=0;
$config['log_path'] = '';
$config['log_file_extension'] = '';
Error Status are already defined In
your_project_dir/system/core/Log.php
protected $_levels = array('ERROR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4)
You've to assign array i.e for errors and info array(1, 2) Method log_message('', '') accepts 2 parameters. First parameter is level (i.e. ERROR or DEBUG or INFO or ALL) & second parameter is message.
Example:
log_message('ERROR', 'Custom error here.');
Remember All default php errors will be part of the log if you assign
$config['log_threshold']=array(1)
For custom Logs: You've to add a new array element in your_project_dir/system/core/Log.php i.e.
protected $_levels = array('ERROR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4, 'CUSTOM' => 5);
Now you can call method as
log_message('CUSTOM', 'Custom message here.'); // This will put just your custom messages in log file
Upvotes: 3
Reputation: 4097
Just as simple like this:
$config['log_threshold'] = 4;
$config['log_path'] = '/logs/';
Upvotes: 2