THELIA Forum

Welcome to the THELIA support and discusssion forum

Offline


Hello ,
I have a case that i need to implement a multible log files, like fore each log that is bigger then 4Mb to create a new file and so one.
I need this to know what is happening to my import (~330K products that are imported via Thelia command),
i try like this:

```
public function setLogger() {
        if (self::$logger == null) {
            self::$logger = Tlog::getNewInstance();
            self::$logger->setPrefix("#DATE #HOUR: ");
            self::$logger->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile");
            self::$logger->setConfig("\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile", 0, "import_log_file.log");
            self::$logger->setConfig("\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile", TlogDestinationRotatingFile::MAX_FILE_SIZE_KB_DEFAULT, "1");
            self::$logger->setConfig("\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile", TlogDestinationRotatingFile::MAX_FILE_COUNT_DEFAULT, "100");
            self::$logger->setLevel(Tlog::ERROR);
        }
        return self::$logger;
    }
```
but without success.

Can someone help me?

Br., Lucian

Offline


Instead of TlogDestinationRotatingFile::MAX_FILE_SIZE_KB_DEFAULT (which is 1024 = 1Mb), use 4096


OpenStudio Toulouse

Offline


I try aloso like that , but, it dosen't genereate a new file , it writes only in on file, and it get to big like a few G , my problem is not the size of the log file, i how to generate new file if the old one has size  4Mb.

Last edited by lucian.criste (23-11-2018 09:31:11)

Offline


I also specify that i use thelia command for this, is not a HTTP request

Offline


also I need to setup foreach import that i have the same logic ,
ex: php Thelia import1:start  should log to log/import1.log  if bigger than 4Mb => log/import1_1[2,3,4,5...].log
php Thelia import2:start  should log to log/import2.log if bigger than 4Mb => log/import2_1[,2,3,4,5...].log
php Thelia import3:start  should log to log/import3.log if bigger than 4Mb => log/import3_1[2,3,4,5...].log
php Thelia import4:start  should log to log/import4.log, if bigger than 4Mb => log/import4_1[ 2,3,4,5...].log

All imports are data that we get from different manufactures/dealers.

Br, Lucian

Last edited by lucian.criste (23-11-2018 10:34:23)

Offline


The calls to setConfig() are wrong. Try this :

    public function setLogger()
    {
        if (self::$logger === null)  {
            self::$logger = Tlog::getNewInstance();
            
            $destination = "\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile";
            
            self::$logger->setDestinations($destination)
                ->setPrefix("#DATE #HOUR: ")
                ->setDestinations($destination)
                ->setLevel(Tlog::ERROR)
                ->setConfig($destination, TlogDestinationRotatingFile::VAR_PATH_FILE,  "import_log_file.log") // Or whatever the filename should be
                ->setConfig($destination, TlogDestinationRotatingFile::MAX_FILE_SIZE_KB_DEFAULT, 4096)
                ->setConfig($destination, TlogDestinationRotatingFile::MAX_FILE_COUNT_DEFAULT, 100)
            ;
        }
        
        return self::$logger;
    }

OpenStudio Toulouse

Offline


No beacause  ,  is validates only one ``if (self::$logger === null)`` on first request and for my import is on request that manages more than 300K products via php Thelia command , but the setConfig() provided by you are working


Thanks!

Last edited by lucian.criste (23-11-2018 12:35:35)