Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log_message codeigniter

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 !

like image 508
Nassim Rebhi Avatar asked May 31 '26 18:05

Nassim Rebhi


2 Answers

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.

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'] = '';
  1. $config['log_threshold'] accepts array (1, 2, 3) or single integer $config['log_path'] accepts path of log file (if you keep it blank the default path will be set and default path will be your_project_dir/application/logs/).
  2. $config['log_file_extension'] accepts log file extension i.e html, txt etc. (if you keep it empty then default extension will be php)
  3. Make sure your log path is write able.

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
like image 30
Zia Avatar answered Jun 02 '26 10:06

Zia