Very simple log rotation
This commit is contained in:
parent
0c02e1efef
commit
b5e2842e00
|
@ -491,6 +491,7 @@ class OC {
|
||||||
self::registerCacheHooks();
|
self::registerCacheHooks();
|
||||||
self::registerFilesystemHooks();
|
self::registerFilesystemHooks();
|
||||||
self::registerShareHooks();
|
self::registerShareHooks();
|
||||||
|
\OCP\BackgroundJob::registerJob('OC\Log\Rotate', OC_Config::getValue("datadirectory", OC::$SERVERROOT.'/data').'/owncloud.log');
|
||||||
|
|
||||||
//make sure temporary files are cleaned up
|
//make sure temporary files are cleaned up
|
||||||
register_shutdown_function(array('OC_Helper', 'cleanTmp'));
|
register_shutdown_function(array('OC_Helper', 'cleanTmp'));
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
* See the COPYING-README file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OC\Log;
|
||||||
|
|
||||||
|
class Rotate extends \OC\BackgroundJob\Job {
|
||||||
|
const LOG_SIZE_LIMIT = 104857600; // 100 MB
|
||||||
|
public function run($logFile) {
|
||||||
|
$filesize = filesize($logFile);
|
||||||
|
if ($filesize >= self::LOG_SIZE_LIMIT) {
|
||||||
|
$this->rotate($logFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function rotate($logfile) {
|
||||||
|
$rotated_logfile = $logfile.'.1';
|
||||||
|
rename($logfile, $rotated_logfile);
|
||||||
|
$msg = 'Log file "'.$logfile.'" was over 100MB, moved to "'.$rotated_logfile.'"';
|
||||||
|
\OC_Log::write('OC\Log\Rotate', $msg, \OC_Log::WARN);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue