KLogger icon indicating copy to clipboard operation
KLogger copied to clipboard

How can i set the max size of a file?

Open GeorgeXiaojie opened this issue 4 years ago • 3 comments

I have a domain process, it write all log to the same file until i restart my process.

GeorgeXiaojie avatar Mar 08 '20 13:03 GeorgeXiaojie

I also want to know it

greedying avatar Sep 29 '21 02:09 greedying

change the function of class Logger: public function setLogFilePath($logDirectory) { if ($this->options['filename']) { if (strpos($this->options['filename'], '.log') !== false || strpos($this->options['filename'], '.txt') !== false) { $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename']; } else { $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'].'.'.$this->options['extension']; } } else { $this->logFilePath = $logDirectory . DIRECTORY_SEPARATOR . $this->options['prefix'] . date('Y-m-d') . '.' . $this->options['extension']; } }

to: public function setLogFilePath($logDirectory) { if ($this->options['filename']) { if (strpos($this->options['filename'], '.log') !== false || strpos($this->options['filename'], '.txt') !== false) { $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename']; } else { $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'].'.'.$this->options['extension']; } } else { $this->logFilePath = $logDirectory . DIRECTORY_SEPARATOR . $this->options['prefix'] . date('Y-m-d') . '.' . $this->options['extension']; $i = 1; while (file_exists($this->logFilePath) && filesize($this->logFilePath) > 5 * 1024 * 1024) { $this->logFilePath = $logDirectory . DIRECTORY_SEPARATOR . $this->options['prefix'] . date('Y-m-d') . '(' . $i . ')' . '.' . $this->options['extension']; $i++; } } }

yutuanbiao avatar Dec 17 '22 07:12 yutuanbiao

$logger = new Katzgrau\KLogger\Logger(DIR . '/runtime/' . date('Y-m'));

yutuanbiao avatar Dec 18 '22 07:12 yutuanbiao