Setting up Log4PHP with CodeIgniter

No BS, the steps are as following –

1. Clone the github project at

>: git clone

2. The ci-log4php directory has 2 folders. Copy and paste the ci_log4php folder in /application/third_party/
3. From the other folder Copy MY_Log.php file.
Open application/config/config.php.
If $config[‘subclass_prefix’] = ‘MY_’;
then place the MY_Log.php file in /application/libraries/
4. Similarly Place the in /application/config folder and log4php_helper.php in /application/helpers folder

5. Edit the file. Set logs logs folder path (If you are using different environment folders for development, production and testing, it would be best to place a different file in each one of them so that while deploying you will not have to change the path)

log4php.appender.default.file = /path/to/ci-app/application/logs/%s.log

6. Set the $config[‘log_threshold’] = 4; in config.php according to :

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

Though I must add that level 4 prints too much log, so in production you might want to keep it to level 1 else your logs will pile up needlessly.

7. Go inside the application folder and run >

chmod -R 777 ./logs

8. Use these commands for logging –




  1. […] 7. Setup logging – Use third party library  ci_log4php Refer my blogpost here […]

  2. From where i can copy/get My_log.php as i dont see any such files lies in CI or log4php environment. what will be content of this file

  3. Ravindra Singh · · Reply

    Thanks.I’ll give it a shot.

    But If there is error on a particular page and 100 of users visited that page then same error will be logged multiple time and if I’m using “Email error logs” then I’ll get 100 of mails for same error.

    So there is any way I can resolve that problem ?

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: