ci-log4php icon indicating copy to clipboard operation
ci-log4php copied to clipboard

Allow array config params

Open skione opened this issue 13 years ago • 17 comments

Can you modify this so that you can use the array config format? Using properties or XML do not allow you to dynamically assign variables from PHP. So for instance, here is a config example from another app: //Logging config $logConfig = array( 'appenders' => array( 'default' => array( 'class' => 'LoggerAppenderRollingFile', 'layout' => array( 'class' => 'LoggerLayoutTTCC', ), 'params' => array( 'file' => BASE_APP_PATH.'log/'.$db.'.log', 'maxFileSize' => '1MB', 'maxBackupIndex' => 5, ), ), ), 'rootLogger' => array( 'level'=>'WARN', 'appenders' => array('default'), ), );

    Logger::configure($logConfig);
    $log = Logger::getLogger('myLogger')

As you can see, I dynamically assign the log path and file name based on the instance I am using. Also I find this a bit more intuitive. The properties example is mostly there so it remains similar to log4j. Perhaps you can make it an option?

skione avatar Jul 02 '12 15:07 skione

Hi,

You want to use like this?

$this->load->library('log');
$this->load->helper('log4php');

$this->log->configure($logConfig);
log_debug('hoge');

fukata avatar Jul 03 '12 14:07 fukata

yes that would be perfect (assumed $logConfig is similar to the array I provided as an example).

skione avatar Jul 03 '12 15:07 skione

$ logConfig is setting you need is an array? The path to the configuration file or bad?

fukata avatar Jul 03 '12 15:07 fukata

I was thinking about that, the array should be what passes so you can dynamically assign vars based on data in the application. Having a static file might not work the same unless you can pass it values.

skione avatar Jul 03 '12 15:07 skione

are going to use as a configuration file or php file is useless? https://logging.apache.org/log4php/docs/configuration.html

fukata avatar Jul 03 '12 15:07 fukata

I personally need to be able to pass an array that is generated based on my code but being able to get the configs from a file as well would probably be useful and a more commonly needed feature.

skione avatar Jul 03 '12 15:07 skione

Hi,

I pushed branch feature/php_variable_configurator.

Use like this.

$this->load->library('log');
$this->load->helper('log4php');
$this->log->reConfigure($logConfig, 'LoggerConfiguratorPhpVariable');
log_debug('hoge');

$logConfig is look this. https://logging.apache.org/log4php/docs/configuration.html

Once I was fine if you want to merge to master.

fukata avatar Jul 04 '12 02:07 fukata

Yeah that looks like it would work real well. The one other change request (and I can open a new issue if your prefer), would be to be able to use the installed PEAR version rather than download the entire code for log4php.

skione avatar Jul 04 '12 12:07 skione

Sorry, I changed ci_log4php. because ci_log4php is not original log4php.

fukata avatar Jul 07 '12 06:07 fukata

Might be useful to figure out a way to use the installed PEAR library but not at all necessary. I am testing the new configs now and I will let you know my results.

skione avatar Jul 11 '12 17:07 skione

Does this use the log level set in the array or the config?

skione avatar Jul 11 '12 18:07 skione

I am not getting any logs created. With or without reConfigure I am not getting any logs being generated.

skione avatar Jul 11 '12 18:07 skione

Sorry for the quad post. So it looks like it is not pulling the path from the array and I am not sure if its pulling any settings. When I had uploaded the new version I overwrote the properties file.

skione avatar Jul 11 '12 18:07 skione

Sorry, I found easy bug. Pushed fixed bug to feature/php_variable_configurator. Please retry.

fukata avatar Jul 12 '12 05:07 fukata

I am getting a fatal error: Fatal error: Class 'LoggerConfiguratorPhpVariable' not found in /var/www/clients/client0/web13/web/application/third_party/ci_log4php/LoggerReflectionUtils.php on line 132

I get this regardless of whether I use the properties file or the array

skione avatar Jul 12 '12 12:07 skione

Sorry,

Fixed it and pushed.

fukata avatar Jul 13 '12 02:07 fukata

Hi,I did all operations according to instruction,but I find the code snippet in readme invoke the codeigniter log. $_log =& load_class('Log'); Is this right? I print in the codeigniter Log.php,It do invoke Log.php

cuihuanhuan avatar Jun 30 '17 12:06 cuihuanhuan