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

Prevent logfile from growing unlimited #1712

Merged
merged 6 commits into from
Dec 11, 2017
Merged

Prevent logfile from growing unlimited #1712

merged 6 commits into from
Dec 11, 2017

Conversation

kevinpapst
Copy link
Contributor

A first hack, that makes sure the users logfile will never exceed the size of 500kB.

At least partially fixes #1562

lib/Minz/Log.php Outdated
* @param $file_name
* @throws Minz_PermissionDeniedException
*/
protected static function checkForLogfileSize($file_name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objections here, but why not just checkLogSize or something? What's the "for" about? :-P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahaha, lets see if I can manage to add at least one PR in the future without a wording issue from your side ;-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the PR where I noticed that I somehow typod my own name really counts. :-P

Copy link
Member

@Frenzie Frenzie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me, but maybe not quite fine as it is right now to those who want to do their own logfile rotation?

@kevinpapst
Copy link
Contributor Author

Someone probably setup logfile rotation for user specific logfiles ... but the vast majority of users will likely be the ones who pay the price in form of ever growing logfiles.
We could still raise the limit up to 10 MB, which should be enough for 99% of the logfile rotation users, using an interval of 1 day up to 1 week.

@Alkarex Alkarex added this to the 1.9.0 milestone Dec 9, 2017
lib/Minz/Log.php Outdated
@@ -20,6 +20,8 @@ class Minz_Log {
const NOTICE = 8;
const DEBUG = 16;

const MAX_LOG_SIZE = 512000; // 500kB
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put a define in constants.php and here, something like

if (!defined('MAX_LOG_SIZE')) {
	define('MAX_LOG_SIZE', 512000);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

lib/Minz/Log.php Outdated
* @throws Minz_PermissionDeniedException
*/
protected static function checkLogfileSize($file_name) {
if (file_exists($file_name) && filesize($file_name) > self::MAX_LOG_SIZE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think file_exists() is superfluous, especially since the file can vanish before the next instruction filesize().
Something like @filesize() should be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can use the shutup operator as well, thought you wouldn't like it.

lib/Minz/Log.php Outdated
*/
protected static function checkLogfileSize($file_name) {
if (file_exists($file_name) && filesize($file_name) > self::MAX_LOG_SIZE) {
if (!unlink($file_name)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to truncate the file, not delete it :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? If we can delete it, we can create it with file_put_contents later on again. Yes, I can use file_put_contents with an empty string as well if you think it makes a difference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep the newest messages.
I think the algorithm could be to divide the logfile by 2 when it increases above a threshold (delete first half of the file).
It is probably not needed to care about keeping entire lines.

lib/Minz/Log.php Outdated
protected static function checkLogfileSize($file_name) {
$maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 512000;
if (@filesize($file_name) > $maxSize) {
if (file_put_contents($file_name, '') === false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep the newest messages.
I think the algorithm could be to divide the logfile by 2 when it increases above a threshold (delete first half of the file).
It is probably not needed to care about keeping entire lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, go ahead and adapt the PR. I don't see a use-case that justifies the effort. After using FreshRSS for more than a year, I did not take even one look into the log - its running to smooth ;-) I did not even know that it existed until I read #1562 and found out that my log file was impressive large as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3a4f23b

@Alkarex
Copy link
Member

Alkarex commented Dec 10, 2017

Ups, a few more fixes are on their way... Done.

@Alkarex
Copy link
Member

Alkarex commented Dec 10, 2017

I have increased the default limit to 1MB, after which the log is divided by 2.
With such a limit, a custom daily logrotate should still be fine, and if not, the value can be increased in constants.php.
Comments?

*/
protected static function ensureMaxLogSize($file_name) {
$maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 1048576;
if ($maxSize > 0 && @filesize($file_name) > $maxSize) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I would still solve that in a different way, all these low level calls make me nervous... if you really want to keep the old logs, why not just rename the "current.log" to "backup.log". The task would be done in one call and less magic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the logic would be more complicated to show the logs in the UI, needing to read more than one log. Similarly, the logic for logrotate would also be more complicated. Furthermore, it would only push the problem further, by not deleting old logs if we keep them under a new name.

@Alkarex
Copy link
Member

Alkarex commented Dec 11, 2017

This seems to work fine on my server, with several logs rotated as expected.
Let's give it a try :-) Please shout if you spot any problem.

@Alkarex Alkarex merged commit 27c3092 into FreshRSS:dev Dec 11, 2017
Alkarex added a commit that referenced this pull request Dec 11, 2017
@kevinpapst kevinpapst deleted the logfilesize branch December 11, 2017 21:19
@kevinpapst
Copy link
Contributor Author

Ok, I will copy a larger log file from /var/log/ over and see what happens - as a simulation for users who are running FreshRSS for a long time without noticing that the log file kept on growing. There might be quite a bigger group of users with such an issue.

@kevinpapst
Copy link
Contributor Author

kevinpapst commented Dec 11, 2017

Ok, I ran actualize_script.php for only one missing feed and with a 16MB log file.
On my non-virtualized root server that took:
Feed actualizations took 0 day(s), 0 hour(s), 0 minute(s) and 0 seconds for 1 users
Afterwards the log file was as expected 513kb

Same test setup but a 420MB log file took about 3 seconds to process, great work!

@Alkarex
Copy link
Member

Alkarex commented Dec 11, 2017

Thanks for the test!

@Alkarex Alkarex modified the milestones: 1.9.0, 1.8.1 Dec 12, 2017
Alkarex added a commit to Alkarex/FreshRSS that referenced this pull request Dec 16, 2017
Alkarex added a commit to Alkarex/FreshRSS that referenced this pull request Dec 16, 2017
Alkarex added a commit to Alkarex/FreshRSS that referenced this pull request Dec 16, 2017
Alkarex added a commit to Alkarex/FreshRSS that referenced this pull request Jan 2, 2018
FreshRSS#907

CURLOPT_FOLLOWLOCATION open_basedir bug (FreshRSS#1657)

CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set
FreshRSS#1655 (comment)
https://stackoverflow.com/questions/6918623/curlopt-followlocation-cannot-be-activated
Manual merge dev

Add an entry in the subscription tool page

I reworked @Alkarex idea proposed in FreshRSS#1292. I though it was a good idea to merge everything in the same location.

Improve translation tools

I was not happy with the previous version. I refactored everything to make it reusable.
It allows me do do more verifications and to build a tool to handle the files themselves.

Merge pull request FreshRSS#1660 from aledeg/api-subscription-tool

Add an entry in the subscription tool page
Merge pull request FreshRSS#1658 from aledeg/improve-i18n-tools

Improve translation tools
Changelog 1247

FreshRSS#1660
FreshRSS#1292
FreshRSS#1247

Merge branch 'FreshRSS/dev' into github-update

[i18] nl/sub: add a few translations
Merge pull request FreshRSS#1661 from FreshRSS/Frenzie-patch-1

[i18] nl/sub: add a few translations
Reworded changelog 1247

FreshRSS#1660
FreshRSS#1292
FreshRSS#1247

Merge branch 'dev' of https://github.com/FreshRSS/FreshRSS into FreshRSS/dev

CLI optimize database (FreshRSS#1663)

CLI optimize database FreshRSS#1583
And VACUUM in SQLite FreshRSS#918
Add VACUUM for PostgreSQL (Not tested yet)
A bit of Apache documentation (FreshRSS#1670)

FreshRSS#1666
FreshRSS#1669
FreshRSS#908
Merge branch 'FreshRSS/dev' into github-update

Delete unneeded update files

Move update scripts

Merge branch 'staging-branch' into github-update

Fix Travis syntax

Fix typo in nl i18n (FreshRSS#1675)


improve zh-cn i18n (FreshRSS#1678)


Move translation tools into the cli folder (FreshRSS#1673)

Translation tools must be used on cli. It is better to have them in the cli folder.
Add a Mastodon share (FreshRSS#1674)

See FreshRSS#1521 
Minor language

Small fix Mastodon share

$a['method'] can be undefined.
FreshRSS#1674
FreshRSS#1521

Changelog Mastodon

Merge pull request FreshRSS#1682 from Alkarex/fix_mastodon_share

Small fix Mastodon share
Merge branch 'FreshRSS/dev' into github-update

More update

Split post-update in disctinct file

Post-update will thus contain code from the new version

Better case for git

Fix link encoding in API (FreshRSS#1686)

FreshRSS#1683
Alkarex/EasyRSS#35
A bit of documentation for the API (FreshRSS#1689)

FreshRSS#1687
FreshRSS#443 (comment)

Merge branch 'FreshRSS/dev' into github-update

[docs] Configuration: some stylistic improvements (FreshRSS#1693)

The main purpose is to fix the `imapcted` typo that was exposed by FreshRSS#1259 (comment)
[FIX] FreshRSS#1690 - Also check pdo_pgsql extension in check_install()

[ADD] 'blankoworld' as contributor in CREDITS

Changelog 1690

FreshRSS#1690
FreshRSS#1691
FreshRSS#1692

I18n - DE (FreshRSS#1698)

* added missing german translations
Call idn_to_ascii with INTL_IDNA_VARIANT_UTS46

Under PHP 7.2, calling `idn_to_ascii($idn)` results in a deprecation warning: 'INTL_IDNA_VARIANT_2003 is deprecated'
See https://secure.php.net/manual/en/function.idn-to-ascii.php 

Therefore, if possible, `idn_to_ascii($idn, 0, INTL_IDNA_VARIANT_UTS46)` should be used instead. `INTL_IDNA_VARIANT_UTS46` was introduced in PHP 5.4, so on versions before that, `idn_to_ascii($idn)` must still be used.

Fixed FreshRSS#1699
A bit more for git updates

Documentation updates (FreshRSS#1697)

* added documentation about updating FreshRSS
moved Installation to admin directory
linked some already existing documentation files
Update panel shows latest version message as success (FreshRSS#1701)

show latest version message as success, FIXES FreshRSS#1586
Merge branch 'FreshRSS/master' into FreshRSS/dev

Remove forgotten punycode line

Credits Craig Andrews

Merge pull request FreshRSS#1700 from candrews/patch-1

Call idn_to_ascii with INTL_IDNA_VARIANT_UTS46
Changelog  1586 1698 1699

FreshRSS#1586
FreshRSS#1701
FreshRSS#1698
FreshRSS#1699
FreshRSS#1700

Merge branch 'dev' of https://github.com/FreshRSS/FreshRSS into FreshRSS/dev

Merge branch 'FreshRSS/dev' into github-update

Add more glyphs for opensans font (FreshRSS#1032)

* Add more glyphs for opensans font

* Update .htaccess to support woff2 file format

* Fixed browser support for new font face

* Fixed Origine theme css and .htaccess

* Deleted unneeded fonts

* Added stylefiles for OpenSans font

* Fixed all themes with new font css

* Avoid additional CSS file

* htaccess cache control public

* Font casing bug

* Remove TTF font

Too big, low need https://caniuse.com/#search=woff

* Changelog 1032

FreshRSS#1032
FreshRSS#1028

Extension function to override entry hash (FreshRSS#1707)

Extension function to override entry hash
FreshRSS#1706


Merge branch 'FreshRSS/dev' into github-update

Show existing extensions in admin panel (FreshRSS#1708)

* first draft

* display installed extension state

* fixed whitespace vs tabs

* added translation in all languages

* added error checks and log messages

* fixed tabs vs whitespace

* another try in fixing whitespaces

* another try in fixing whitespaces

* improved extension list translations

* using JSON from official extension repo

* improved version compare

* updated translations

* French translation

make sure that we do not exceed a certain file size for the users log file

renamed method

incorporated code review feedback

added new extension hook
using hook for reading modes in navigation

refactored ReadingModes to Model

Log rotation, use Minz_Log, new log constants

ADMIN_LOG, API_LOG, PSHB_LOG

Check requirement in CLI script (FreshRSS#1711)

* check requirements in actualize_script before executing, fixes FreshRSS#1710

* removed empty whiteline

* testing all requirements

* incorporated code review feedback

* removed code that is already executed in _cli.php

* added newline at eof

* fixed include problems

* fixed include problems

Merge branch 'dev' into logfilesize
Merge branch 'dev' into logfilesize
Changelog 1708 1711

FreshRSS#1708
FreshRSS#1711

Merge pull request FreshRSS#1712 from kevinpapst/logfilesize

Prevent logfile from growing unlimited
Changelog 1712

FreshRSS#1712
FreshRSS#1562

Use __DIR__ for relative include and require

For uniformity, and to avoid having PHP searching in include_path.
http://php.net/manual/function.include.php
FreshRSS#1715
FreshRSS#1711 (comment)

Merge pull request FreshRSS#1717 from Alkarex/dir_in_require

Use __DIR__ for relative include and require
fixed bug in catch block
added types to docblocks

Merge pull request FreshRSS#1724 from kevinpapst/exception-bug

ExtensionManager fixes
[doc] Extensions: translate various sections from French

See FreshRSS#1697 (comment)

* lowercase dir as pointed out by @kevinpapst in FreshRSS#1704 (comment)

* Add French translation with improvements suggested by @aledeg

Merge branch 'dev' into hebrew-i18n
Fix whitespace

Add message after log rotation

FreshRSS#1712
FreshRSS#1562

Minz Dispatcher Controllers path

FreshRSS#1704

Customisable constants.local.php (FreshRSS#1725)

FreshRSS#1562
FreshRSS#1607
FreshRSS#1656
FreshRSS#1705
FreshRSS#1712
Merge pull request FreshRSS#1726 from Alkarex/message_log_rotation

Add message after log rotation
i18n hebrew more

18n Hebrew more 2

Changelog 1716 1724 1725

https://github.com/FreshRSS/FreshRSS/pull/1716
FreshRSS#1724
FreshRSS#1725

Merge branch 'FreshRSS/dev' into Minz_Dispatcher_paths

Changelog 1729

Merge pull request #1716 from FreshRSS/hebrew-i18n

Add hebrew translation
Changelog 1716

https://github.com/FreshRSS/FreshRSS/pull/1716

Merge pull request FreshRSS#1729 from Alkarex/Minz_Dispatcher_paths

Minz Dispatcher Controllers path
added .editorconfig with basic settings

Minz Controllers directory uppercase

FreshRSS#1729

Merge pull request FreshRSS#1704 from Frenzie/doc-translate-extensions

[doc] Extensions: translate various sections from French
Merge pull request FreshRSS#1732 from kevinpapst/editorconfig

Added .editorconfig
Changelog 1697, 1704, 1732

FreshRSS#1697
FreshRSS#1704
FreshRSS#1732

Merge branch 'dev' of https://github.com/FreshRSS/FreshRSS into FreshRSS/dev

fixed bug when adding a category and feed at the same time (FreshRSS#1731)

fixed bug when adding a category and feed at the same time

Changelog 1731

FreshRSS#1731

Fix favicon for open_basedir (FreshRSS#1733)

Remove open_basedir warning for CURLOPT_FOLLOWLOCATION with PHP 5.6.0- https://bugs.php.net/bug.php?id=65646
Remove warning for CURLOPT_FOLLOWLOCATION with open_basedir (FreshRSS#1734)

For PHP 5.6.0- http://www.php.net/ChangeLog-5.php#5.6.0
https://bugs.php.net/bug.php?id=65646
FreshRSS#1733
FreshRSS#1657
FreshRSS#1655
Prepare release of FreshRSS 1.9.0

Merge pull request FreshRSS#1720 from FreshRSS/dev

FreshRSS 1.9.0
Update FreshRSS version to 1.9.0

Merge branch 'FreshRSS/dev' into FreshRSS/master

[docs] Extensions: fix typo (FreshRSS#1735)


Merge branch 'FreshRSS/dev' into FreshRSS/master

New development version 1.9.1-dev

PHP 7.2: Fix a warning when retrieving the list of entries (FreshRSS#1739)

When retrieving the list of entries when the context was 'all' or 'starred', there was the following warning:

> Warning: count(): Parameter must be an array or an object that implements Countable in /home/alexis/FreshRSS/app/Controllers/indexController.php on line 206

I fixed that by changing how the array is tested.
Fixes link to the "update guidelines" (FreshRSS#1740)


Fixes link to the "update guidelines" (FreshRSS#1740)


Minor changes (FreshRSS#1747)


Tiny additions to .editorconfig (FreshRSS#1744)


Improving README in English and French (FreshRSS#1746)


Merge branch 'FreshRSS/master' into FreshRSS/dev

Adding new items to force-https.default.txt (FreshRSS#1745)


credits  RyDroid

FreshRSS#1747
FreshRSS#1746
FreshRSS#1745
FreshRSS#1744

[doc] Editing for better style (FreshRSS#1736)

* Also removed references to Persona authentication.
* Changed code comment about Persona because it's for HTTP auth
  in general. See FreshRSS@3d87609
  and FreshRSS#358 (comment)
[i18n] Add translation ignore/nl (FreshRSS#1752)


Add shortcuts to switch views (FreshRSS#1755)


Add mute strategy configuration (FreshRSS#1750)


Minor syntax

Merge pull request FreshRSS#1714 from kevinpapst/hook-readingmodes

Added extension hook for reading modes
Changelog 1739, 1745, 1750, 1755

FreshRSS#1739
FreshRSS#1745
FreshRSS#1750
FreshRSS#1755

Fix login bug when HTTP REMOTE_USER changes

YunoHost-Apps/freshrss_ynh#33

Merge pull request FreshRSS#1756 from Alkarex/YunoHost_HTTP_Auth

Fix login bug when HTTP REMOTE_USER changes
Changelog 1756

FreshRSS#1756
YunoHost-Apps/freshrss_ynh#33

Merge branch 'dev' of https://github.com/FreshRSS/FreshRSS into FreshRSS/dev

Fix shortcuts triggering view switching

Merge pull request FreshRSS#1758 from aledeg/fix-nav-buttons

Fix shortcuts triggering view switching
Merge branch 'dev' into github-update
Merge branch 'dev' into github-update
javerous pushed a commit to javerous/FreshRSS that referenced this pull request Jan 20, 2020
Prevent logfile from growing unlimited
javerous pushed a commit to javerous/FreshRSS that referenced this pull request Jan 20, 2020
javerous pushed a commit to javerous/FreshRSS that referenced this pull request Jan 20, 2020
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

Successfully merging this pull request may close these issues.

3 participants