Log_message codeigniter

喜欢而已 提交于 2019-12-13 04:42:17

问题


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 !


回答1:


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




回答2:


Just as simple like this:

$config['log_threshold'] = 4;

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



回答3:


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


来源:https://stackoverflow.com/questions/33389366/log-message-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!