Log_message codeigniter Log_message codeigniter codeigniter codeigniter

Log_message codeigniter


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.


Just as simple like this:

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


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.');

RememberAll 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.phpi.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