bernhard Posted April 12, 2023 Share Posted April 12, 2023 Today I've had a site with a logfile that has grown to 70MB over the years... PW is so low-maintenance that I usually just deploy and forget ? Now while having that 70MB is not really an issue - all parameters still by far in the greens - it's definitely something that could be improved. So I'm wondering: Do you do regular maintenance on your site? Or do you have a script in place that prunes logfiles? I could think of some kind of notification system that sends me an email if one of the logfiles grows over a defined filesize. Or a cronjob that automatically prunes logs to x days. What dou you think? How do you handle logs? 1 Link to comment Share on other sites More sharing options...
Krlos Posted April 12, 2023 Share Posted April 12, 2023 Same as you, deploy and forget. I've noticed that when hosting providers update something, the log file starts growing with warning logs. I usually realize months later. I love PW? 1 Link to comment Share on other sites More sharing options...
wbmnfktr Posted April 12, 2023 Share Posted April 12, 2023 4 hours ago, bernhard said: Today I've had a site with a logfile that has grown to 70MB Welcome to my world... kind of. 4 hours ago, bernhard said: Do you do regular maintenance on your site? My main hoster and most other setups I know handle log file rotation by default - so files don't grow that large and older log files will be deleted after either a few weeks/months or in case there are too many files in the folder. Can't remember the tool you use but it should have something like this as well. I remember Webmin had something back in the days. 4 hours ago, bernhard said: How do you handle logs? In bigger projects and when the client wants me to take care of most of the things I check the log files at least weekly - or when using a CDN - monthly and then dig through error-logs. Link to comment Share on other sites More sharing options...
gebeer Posted April 13, 2023 Share Posted April 13, 2023 There's 3 Link to comment Share on other sites More sharing options...
MarkE Posted April 13, 2023 Share Posted April 13, 2023 16 hours ago, bernhard said: Or do you have a script in place that prunes logfiles? That’s what I do. Part of a regular cron batch job. 1 Link to comment Share on other sites More sharing options...
BrendonKoz Posted April 13, 2023 Share Posted April 13, 2023 20 hours ago, wbmnfktr said: My main hoster and most other setups I know handle log file rotation by default - so files don't grow that large and older log files will be deleted after either a few weeks/months or in case there are too many files in the folder. Since bernhard didn't clarify, I think he's referring to ProcessWire logs, not system or server logs. My host handles rotation of server log files, but not log files generated by scripts installed by me; does yours (that'd be both neat and scary!)? So, I believe the maintenance being discussed here are the log files found in site/assets/logs/*...? Thus far: deploy and forget, but now I'm going to have to look!!! I'd personally be fine with keeping logs to a maximum number of days old. If I wasn't around or didn't check on something more than 30 days prior it's unlikely I'd be interested in it - though that's just me. 1 Link to comment Share on other sites More sharing options...
wbmnfktr Posted April 13, 2023 Share Posted April 13, 2023 That's a very good call actually. My first thought were server logs. The ProcessWire logs get pruned after a while by the module @gebeer mentioned. Link to comment Share on other sites More sharing options...
bernhard Posted April 13, 2023 Author Share Posted April 13, 2023 1 hour ago, BrendonKoz said: Since bernhard didn't clarify, I think he's referring to ProcessWire logs, not system or server logs. My host handles rotation of server log files, but not log files generated by scripts installed by me; does yours (that'd be both neat and scary!)? So, I believe the maintenance being discussed here are the log files found in site/assets/logs/*...? Yeah, sorry, been talking about the PW logfiles of course ? That's why I posted it in "PW general support" and not "dev talk", but I changed the post title to make it more obvious, thx! Now I understand the answer of @wbmnfktr better ? I'm not sure yet if I really like to auto-prune logs to a given size/length/age... I think I'd prefer to get an email when logs grow too much. 9 hours ago, MarkE said: That’s what I do. Part of a regular cron batch job. Do you have some code to share with us? 1 Link to comment Share on other sites More sharing options...
MarkE Posted April 14, 2023 Share Posted April 14, 2023 22 hours ago, bernhard said: Do you have some code to share with us? Simples: In init.php wire()->addHook('LazyCron::everyDay', null, 'batchRun'); and then in your hook: wire()->log->prune('debug', $days); where $days is set however you want In my case I aded a cronjob to access the site at night so that the LazyCron fires then. 4 Link to comment Share on other sites More sharing options...
bernhard Posted June 7, 2023 Author Share Posted June 7, 2023 Ok a client wanted me to do some gdpr imrovements so I added this to my Site.module.php ? public function init() { ... $this->wire->addHookAfter('LazyCron::everyDay', $this, 'gdpr'); } public function gdpr() { // delete old rockforms logs $logs = $this->wire->pages->find([ 'template' => RockFormsLogPage::tpl, ['created', '<', time() - RockMigrations::oneMonth], 'include' => 'all', // also trashed pages! ]); foreach ($logs as $log) $log->delete(); // delete old processwire logs $this->wire->log->pruneAll(30); } So RockMigrations just got an update to support time constants: // time constants (seconds) // see https://i.imgur.com/vfTasHa.png const oneMinute = 60; const oneHour = self::oneMinute * 60; const oneDay = self::oneHour * 24; const oneWeek = self::oneDay * 7; const oneMonth = self::oneDay * 30; const oneYear = self::oneDay * 365; And I also found there is $wire->log->pruneAll($days) which is also handy ? Again PW has all the tools to make very custom needs possible with just a few simple lines of code! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now