CodeIgniter Forums
change config['log_path'] on the fly - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: change config['log_path'] on the fly (/showthread.php?tid=70149)



change config['log_path'] on the fly - eminence - 03-01-2018

I am trying to specify my log directory from MY_Controller (my base class for application/controllers/*.php) depending on the controller class being called. The clog directory was specified using 
Code:
$this->config->set_item("log_path",APPPATH.'logs'.DIRECTORY_SEPARATOR.$this->router->class.DIRECTORY_SEPARATOR);

in the MY_Controller::__construct(). I have a custom log function in MY_Controller::log() which in turn calls CI's log_message().
All the possible log directories exists and have permission of 777. 

Code:
$this->config->item('log_path');

 always return the correct expected log directory.
The issue despite the default log directory being changed successfully to another directory, the string to be logged is being logged into the default log directory (application/logs).
Any help will be appreciated. Thanks.


RE: change config['log_path'] on the fly - InsiteFX - 03-01-2018

Try this, it may need to be put into the CodeIgniter global space.

PHP Code:
$this->load->vars($this->config->item('log_path')); 



RE: change config['log_path'] on the fly - Narf - 03-01-2018

This directive is not supposed to be changed at runtime, and you shouldn't try to.
Quite a lot of messages are logged before you ever have the chance to try altering the path.

(03-01-2018, 06:17 AM)InsiteFX Wrote: Try this, it may need to be put into the CodeIgniter global space.

PHP Code:
$this->load->vars($this->config->item('log_path')); 

... and this cannot possibly help, in any situation. Totally unrelated.

I've lost count of how many times I've had to correct you for stuff like this, @InsiteFX. I know you're trying to help, but you can't just throw random suggestions, because when they don't work, you're doing the very opposite - people waste time with it and are often put in an entirely wrong direction.


RE: change config['log_path'] on the fly - eminence - 03-01-2018

Thanks @Narf. Is there a way through which the log directory can be made dynamic? I am of the opinion that this should be possible.


RE: change config['log_path'] on the fly - Narf - 03-01-2018

No. I don't understand why you should it should be possible, but even if we wanted to modify the entire framework to allow this, we'd probably still fall short.


RE: change config['log_path'] on the fly - eminence - 03-02-2018

OK. Narf, does this apply to "log_path" alone or all CI config params? 

CI gave room for config params modification using
PHP Code:
$this->config->set_item("index","new_value"
obviously because those config params can be modified. Also, there is no documentation specifying any config params which can not be changed. This is why i am of the opinion that it should/could be possible.


RE: change config['log_path'] on the fly - Narf - 03-02-2018

A few other ones have the same limitation, but it's very far from all of them.

It's very simple - some directives just have to go into effect before you ever have the chance to try modifying them (if you do at all; there's no guarantee that a controller will be instantiated).


RE: change config['log_path'] on the fly - eminence - 03-02-2018

All right. Thanks for your time.