Log_message codeigniter

2019-09-11 15:40发布

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 !

3条回答
何必那么认真
2楼-- · 2019-09-11 16:33

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
查看更多
贪生不怕死
3楼-- · 2019-09-11 16:36

I would use FCPATH $config['log_path'] = FCPATH . '/application/logs/'; once you have set path refresh page. $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']);

Folder Must Be Writable CHMOD 700

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-09-11 16:40

Just as simple like this:

$config['log_threshold'] = 4;

$config['log_path'] = '/logs/';
查看更多
登录 后发表回答