• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
change config['log_path'] on the fly

#1
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.
Reply

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

PHP Code:
$this->load->vars($this->config->item('log_path')); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
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.
Reply

#4
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.
Reply

#5
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.
Reply

#6
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.
Reply

#7
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).
Reply

#8
All right. Thanks for your time.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.