Welcome Guest, Not a member yet? Register   Sign In
CI4 Customizing Logger filename
#1

Hi,
I am a real fan of CI3 for years ...   and recently decided to create a new project using CI4 .
Couldn't find a way to have multiple log files....
I usually create my own log helper , and have tricks that I like to customize on the logging.
One of the important one , is having the ability to give the logger a different log file name .
So instead of having one log :   log-YYY-MM-DD.log    , I'd like to have :
log-billing-YYY-MM-DD.log
log-accounts-YYY-MM-DD.log
log-orders-YYY-MM-DD.log
log-products-YYY-MM-DD.log
etc ....

Can't find a way to do it.

I saw this post ,   https://forum.codeigniter.com/thread-78665.html
AngelRodriguez is showing how to modify the log path

For instance :
PHP Code:
use Config\Logger as LoggerConfig;
use 
CodeIgniter\Log\Logger as Logger;
function 
lg($level$message) {

        // log with default config
        log_message('critical''test {file} {line}');

        // log with custom
        $loggerConfig = new LoggerConfig();

        // or just edit path parameter
        $customPath 'logs/otherfolder/';
        $loggerConfig->handlers['CodeIgniter\Log\Handlers\FileHandler']['path'] = WRITEPATH $customPath;

        // you need to create the folder manually first
        
        
//then create new instance with the config
        $logger = new Logger($loggerConfig);
        $logger->log('critical''test other folder {file} {line}'); 

}


but I want also to modify the filename .... 
Reply
#2

Create your own FileHandler based on (extends) system/Log/Handlers/FileHandler.php,
and configure to use it in app/Config/Logger.php.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB