cosmocode / dokuwiki-plugin-logstats

temporary fork of the DokuWiki logstats plugin
1 stars 6 forks source link

Current year in the name of the access.log file #21

Open ookris opened 5 years ago

ookris commented 5 years ago

Hi Is it possible to add the current year to the name of the generated * .log file, e.g. 2018_access.log? And for more advanced users, you could add the option to generate a file in a week or month. It would cause that the log file would not get too large.

ookris commented 5 years ago

Solution

open /conf/metadata.php, add

$meta['accesslog_annual'] = array('onoff');

open /conf/default.php, add

$conf['accesslog_annual'] = 0;

open /lang/en/settings.php, add

$lang['accesslog_annual'] = 'Enable the annual log file? This will add the current year to the log file name e.g. <code>2018-access.log</code>';

open action.php, find

// determine log, relative paths resolve to meta dir
        $dir = dirname($this->getConf('accesslog'));
        $log = basename($this->getConf('accesslog'));
        if($dir == '.' || $dir == '' || !is_dir($dir)){
            $dir = fullpath($conf['metadir'].'/'.$dir);
        }
        return io_saveFile("$dir/$log", $logline, true);

change to

// determine log, relative paths resolve to meta dir
        $year = date("Y");
        $dir = dirname($this->getConf('accesslog'));
        if($this->getConf('accesslog_annual') == 1) {
            $log = basename($year . '-' . $this->getConf('accesslog'));
        } else {
            $log = basename($this->getConf('accesslog'));
        }
        if($dir == '.' || $dir == '' || !is_dir($dir)){
            $dir = fullpath($conf['metadir'].'/'.$dir);
        }

        return io_saveFile("$dir/$log", $logline, true);

Save all files and send to the server. Open the settings page and change the new option.

zrzut ekranu 2018-11-23 o 20 26 11