ADD ERROR LOG FILE IN CODEIGNITER

Edit your application/config/config.php

to enable error logs choose “threshold options 1 to 4” to OFF choose “0”.

/*
|————————————————————————–
| Error Logging Threshold
|————————————————————————–
|
| If you have enabled error logging, you can set an error threshold to
| determine what gets logged. Threshold options are:
| You can enable error logging by setting a threshold over zero. The
| threshold determines what gets logged. Threshold options are:
|
| 0 = Disables logging, Error logging TURNED OFF
| 1 = Error Messages (including PHP errors)
| 2 = Debug Messages
| 3 = Informational Messages
| 4 = All Messages
|
| For a live site you’ll usually only enable Errors (1) to be logged otherwise
| your log files will fill up very fast.
|
*/
$config[‘log_threshold’] = 0; //default 0

/*
|————————————————————————–
| Error Logging Directory Path
|————————————————————————–
|
| Leave this BLANK unless you would like to set something other than the default
| application/logs/ folder. Use a full server path with trailing slash.
|
*/
$config[‘log_path’] = ‘assets/error_logs/’;

/*
|————————————————————————–
| Date Format for Logs
|————————————————————————–
|
| Each item that is logged has an associated date. You can use PHP date
| codes to set your own date formatting
|
*/
$config[‘log_date_format’] = ‘Y-m-d H:i:s’;

I choose my error_logs  in different folder instead of “application/logs” make sure the folder is in writable permission.

after that………use the “log_message()” function. (3 types = info, debug, error)

Example: insert  any messages anywhere in your code to track the errors!!

log_message(‘error’, ‘error message in this line’);

log_message(‘debug’, ‘debug message in this line’);

log_message(‘info’, ‘info message in this line’);

OUTPUT: in your assets/error_logs/ directory………..”log-YYYY-MM-DD.php” file.

ex. log-2014-06-24.php

THE CONTENT OF THE FILE:

<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’); ?>

DEBUG – 2014-06-24 09:02:35 –> Config Class Initialized
DEBUG – 2014-06-24 09:02:35 –> Hooks Class Initialized
DEBUG – 2014-06-24 09:02:35 –> Utf8 Class Initialized
DEBUG – 2014-06-24 09:02:35 –> UTF-8 Support Enabled
DEBUG – 2014-06-24 09:02:35 –> URI Class Initialized
DEBUG – 2014-06-24 09:02:35 –> Router Class Initialized
DEBUG – 2014-06-24 09:02:36 –> Output Class Initialized
DEBUG – 2014-06-24 09:02:36 –> Security Class Initialized
DEBUG – 2014-06-24 09:02:36 –> Input Class Initialized
DEBUG – 2014-06-24 09:02:36 –> Global POST and COOKIE data sanitized
DEBUG – 2014-06-24 09:02:36 –> Language Class Initialized
DEBUG – 2014-06-24 09:02:36 –> Loader Class Initialized
DEBUG – 2014-06-24 09:02:36 –> Config file loaded: application/config/utilities/rm_config.php
DEBUG – 2014-06-24 09:02:36 –> Helper loaded: url_helper
DEBUG – 2014-06-24 09:02:36 –> Helper loaded: form_helper
DEBUG – 2014-06-24 09:02:36 –> Helper loaded: html_helper
DEBUG – 2014-06-24 09:02:36 –> Helper loaded: path_helper
DEBUG – 2014-06-24 09:02:36 –> Database Driver Class Initialized
DEBUG – 2014-06-24 09:02:36 –> Form Validation Class Initialized
DEBUG – 2014-06-24 09:02:36 –> Table Class Initialized
DEBUG – 2014-06-24 09:02:36 –> Controller Class Initialized
ERROR – 2014-06-24 09:02:36 –> error message in this line
DEBUG – 2014-06-24 09:02:36 –> debug message in this line
INFO – 2014-06-24 09:02:36 –> info message in this line
DEBUG – 2014-06-24 09:02:36 –> Final output sent to browser
DEBUG – 2014-06-24 09:02:36 –> Total execution time: 0.1465

Advertisements
This entry was posted in CODE IGNITER. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s