Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i set the max size of a file? #99

Open
GeorgeXiaojie opened this issue Mar 8, 2020 · 3 comments
Open

How can i set the max size of a file? #99

GeorgeXiaojie opened this issue Mar 8, 2020 · 3 comments

Comments

@GeorgeXiaojie
Copy link

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

@greedying
Copy link

I also want to know it

@yutuanbiao
Copy link

yutuanbiao commented Dec 17, 2022

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants