Welcome Guest, Not a member yet? Register   Sign In
Change log_treshold at runtime
#1

[eluser]Zeff[/eluser]
Hi all,

In the configuration file \application\config\config.php, $config['log_treshold'] is set to 1 in in (only errors are logged).

Sometimes, I would be handy to log also an info (eg when someone opens a particular page or write the uid of a logged in user, ...).

Is there a possibility to:
1. Enter more than one level in this config.php file (I don't think so :-)Wink
2. Can I change the 'log_treshold' var at runtime? (and how do I do that with the log class?)

Many thanks in advance!

Best regards,

Zeff
#2

[eluser]PhilTem[/eluser]
You can change the log_threshold at runtime using
Code:
$this->config->set_item('item_name', 'item_value');

However, it is kinda weird seeing you change the config-item at runtime. For your case I'd recommend creating your own logging library which logs things to a database and can be read out from there as well. Since you would not want to mix system logging with application logging - at least I would not want to Wink
#3

[eluser]Zeff[/eluser]
Hi PhilTem,

Thanks for your response, I already tried:
<code>
$this->config->set_item('log_threshold', 3);
log_message('info', 'MyApp: '.$this->session->userdata('uid').' logged in');
</code>
But this doesn't work, I only see error log messages in my logfile, no 'INFO'...

I will take in account your remark about db-driven logging, thanks. I just wanted to quick solution by using the existing log possibilities...

Best regards,

Zeff
#4

[eluser]PhilTem[/eluser]
Ah, dang, right. The Log-class sets the log-threshold on constructing i.e. very early in the page creation process. My bad, sorry for posting that nonsense. You may vote my previous post down Big Grin
And CI_Log does not have a method to initialize the class either just like other CI libs have. You may want to extend CI_Log with MY_Log and either add a initialize method or change the attribute
Code:
protected $_threshold = 1;

to
Code:
public $_threshold = 1;

which then can be changed using
Code:
$this->log->_threshold = 4;
#5

[eluser]Aken[/eluser]
Check out CI's Github repo. The logging library has been updated so you can define an array of log levels that you want to capture, rather than setting a "minimum" level.




Theme © iAndrew 2016 - Forum software by © MyBB