Setting up Log4PHP with CodeIgniter

No BS, the steps are as following -

1. Clone the github project at https://github.com/fukata/ci-log4php

>: git clone https://github.com/fukata/ci-log4php.git

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 log4php.properties in /application/config folder and log4php_helper.php in /application/helpers folder

5. Edit the log4php.properties 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 log4php.properties 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 -

$this->load->helper(‘log4php’);
log_error(‘my_error’);
log_info(‘my_info’);
log_debug(‘my_debug’);

About these ads

One Comment

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

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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: