Daniel Harris
Daniel Harris

Reputation: 1905

How do you disable logging for specific controllers in CodeIgniter?

My web application has many timed looped ajax requests that get content from different controllers and it is increasing my daily log sizes to 2 GB. Is there a way to disable logging only for specific controllers when called? Logging should be disabled upon the first instance of the controller and then re-enabled right before calling the load->view method.

Upvotes: 0

Views: 548

Answers (1)

DFriend
DFriend

Reputation: 8964

As you likely know the error logging thresholds are

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

You should be able to use the following to turn logging off.

$this->config->set_item('log_threshold', 0);

This could be done in specific controller methods or in the controller constructor if you want all its methods to stop logging.

To resume logging, i.e. at the "All Messages" level run this

$this->config->set_item('log_threshold', 4);

Understand that any calls to config->set_item() are NOT persistent. The call does not change the contents of config.php so the next time the site receives a request it will use the log threshold as defined in the config file.

Likewise, if after the level is changed dynamically the config file is reloaded it will overwrite the dynamically assigned value. AFAIK, CodeIgniter only loads the config file(s) once per framework instance. But developers do weird stuff sometimes.

Upvotes: 2

Related Questions