Welcome Guest, Not a member yet? Register   Sign In
Is possible to create logs in another file and folder?
#1

(This post was last modified: 02-22-2021, 11:44 AM by AngelRodriguez.)

Hi,

I want to create logs in different folders with different names. Is it possible? (I'm using CI4 system Logger)

For example:

/logs
    /app
       applog-date.log
       applog-date.log
    /other
       otherlog-date.log
       otherlog-date.log

Thank you
Reply
#2

(02-22-2021, 11:42 AM)AngelRodriguez Wrote: Hi,

I want to create logs in different folders with different names. Is it possible? (I'm using CI4 system Logger)

For example:

/logs
    /app
       applog-date.log
       applog-date.log
    /other
       otherlog-date.log
       otherlog-date.log

Thank you

ci4  already had intergrate logger in write folder see there
Enlightenment  Is  Freedom
Reply
#3

It seems it is possible if you create another Logger instance for another log path by yourself.
Reply
#4

(This post was last modified: 02-23-2021, 03:39 AM by AngelRodriguez.)

(02-22-2021, 04:40 PM)kenjis Wrote: It seems it is possible if you create another Logger instance for another log path by yourself.

Im using 4.0.4 and is not possible in this version change the path. I need to update to 4.1.1 and it works Big Grin

thank you
Reply
#5

Could you please describe exactly how you achieved this.
I am trying to group messages of a similar kind into a separate file. I can’t work out how to change log path at run time.
Reply
#6

(This post was last modified: 03-04-2021, 01:00 PM by AngelRodriguez.)

(03-04-2021, 06:05 AM)motownphilippe Wrote: Could you please describe exactly how you achieved this.
I am trying to group messages of a similar kind into a separate file. I can’t work out how to change log path at run time.


PHP Code:
use Config\Logger as LoggerConfig;
use 
CodeIgniter\Log\Logger as Logger;


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

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

        // you can customize handlers from Config\Logger.php
        /*  $handlers = [
              'CodeIgniter\Log\Handlers\FileHandler' => [
                  'handles'         => [
                      'critical',
                      'alert',
                      'emergency',
                      'debug',
                      'error',
                      'info',
                      'notice',
                      'warning',
                  ],
                  'fileExtension'   => '',
                  'filePermissions' => 0644,
                  'path'            => WRITEPATH. 'logs/',
              ],
          ];

        $loggerConfig->handlers = $handlers;
        */

        // 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}'); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB