2

How to create Error log in PHP Codeigniter Framework? The Error log has Possible to create in localhost ?

3 Answers3

3

Yes you can enable for localhost. just go to applications/config/config.php and add

$config['log_threshold'] = 1;
$config['log_path'] = '';// add your path

$config['log_path'] = '' default will be applications/logs dir

log threshold values :-

0 = Disables logging, Error logging TURNED OFF
1 = Error Messages (including PHP errors)
2 = Debug Messages
3 = Informational Messages
4 = All Messages

For more :- How to do error logging in CodeIgniter (PHP)

Community
  • 1
  • 1
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44
0

Yes you can enable Error log for both localhost and live server. Please do the step by step procedure as stated bellow:

  1. In application > config > config.php change line 183 to $config['log_threshold'] = 4;
  2. Then run your application and you will get the log file with date as name in applicaiton > logs directory.

If you want to log custom error then use the following syntax:

log_message('level', 'message')

Where level can be Error, Debug, Info etc.

Ariful Islam
  • 7,639
  • 7
  • 36
  • 54
0

PHP has an in built system of logging errors.

This file is php_errors.log

This file's locations:

Ubuntu: /var/log/php_errors.log XAMPP (Windows) : /xampp/php/logs/php_errors.log

To write to this log file, simply call a function 'error_log'.

e.g. to write a string to this file error_log('This is a string');

OR

CodeIgniter has some error logging functions built in.

Make your /application/logs folder writable
In /application/config/config.php set
$config['log_threshold'] = 1;
or use a higher number, depending on how much detail you want in your logs
Use log_message('error', 'Some variable did not contain a value.');

To send an email you need to extend the core CI_Exceptions class method log_exceptions(). You can do this yourself or use this. More info on extending the core here

See http://ellislab.com/codeigniter/user-guide/general/errors.html

Pupil
  • 23,834
  • 6
  • 44
  • 66