From f26e7ba5ffb9b6add47d74a7328e6a78a730d6b6 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Sat, 7 Apr 2018 11:44:34 +0200 Subject: [PATCH] Add option to disable logs --- CHANGELOG | 1 + lib/Lutim.pm | 1 + lib/Lutim/Controller.pm | 30 +++++++++++++++--------------- lib/Mounter.pm | 1 + lutim.conf.template | 9 +++++++++ 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9cfb0b3..46ead7f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ Revision history for Lutim - PostgreSQL performance improvments - Move some tasks to recurring instead of being in after_dispatch hook - Built-in image cache system \o/ + - Disable logs option 0.9.6 2018-03-12 - Update translations diff --git a/lib/Lutim.pm b/lib/Lutim.pm index c00f295..e506581 100644 --- a/lib/Lutim.pm +++ b/lib/Lutim.pm @@ -54,6 +54,7 @@ sub startup { db_path => 'minion.db' }, cache_max_size => 0, + quiet_logs => 0, } }); diff --git a/lib/Lutim/Controller.pm b/lib/Lutim/Controller.pm index b2303bc..b4aaf9b 100644 --- a/lib/Lutim/Controller.pm +++ b/lib/Lutim/Controller.pm @@ -36,7 +36,7 @@ sub home { $c->on(finish => sub { my $c = shift; - $c->app->log->info('[HIT] someone visited site index'); + $c->app->log->info('[HIT] someone visited site index') unless $c->config('quiet_logs'); } ); } @@ -157,7 +157,7 @@ sub modify { if ($image->mod_token ne $token || $token eq '') { $msg = $c->l('The delete token is invalid.'); } else { - $c->app->log->info('[MODIFICATION] someone modify '.$image->filename.' with token method (path: '.$image->path.')'); + $c->app->log->info('[MODIFICATION] someone modify '.$image->filename.' with token method (path: '.$image->path.')') unless $c->config('quiet_logs'); $image->delete_at_day(($c->param('delete-day') && ($c->param('delete-day') <= $c->max_delay || $c->max_delay == 0)) ? $c->param('delete-day') : $c->max_delay); $image->delete_at_first_view(($c->param('first-view')) ? 1 : 0); @@ -194,7 +194,7 @@ sub modify { return $c->redirect_to('/'); } } else { - $c->app->log->info('[UNSUCCESSFUL] someone tried to modify '.$short.' but it does\'nt exist.'); + $c->app->log->info('[UNSUCCESSFUL] someone tried to modify '.$short.' but it does\'nt exist.') unless $c->config('quiet_logs'); # Image never existed my $msg = $c->l('Unable to find the image %1.', $short); @@ -227,7 +227,7 @@ sub delete { } elsif ($image->enabled() == 0) { $msg = $c->l('The image %1 has already been deleted.', $image->filename); } else { - $c->app->log->info('[DELETION] someone made '.$image->filename.' removed with token method (path: '.$image->path.')'); + $c->app->log->info('[DELETION] someone made '.$image->filename.' removed with token method (path: '.$image->path.')') unless $c->config('quiet_logs'); $c->delete_image($image); return $c->respond_to( @@ -261,7 +261,7 @@ sub delete { } ); } else { - $c->app->log->info('[UNSUCCESSFUL] someone tried to delete '.$short.' but it does\'nt exist.'); + $c->app->log->info('[UNSUCCESSFUL] someone tried to delete '.$short.' but it does\'nt exist.') unless $c->config('quiet_logs'); # Image never existed return $c->respond_to( @@ -465,7 +465,7 @@ sub add { ->write; # Log image creation - $c->app->log->info('[CREATION] '.$ip.' pushed '.$filename.' (path: '.$path.')'); + $c->app->log->info('[CREATION] '.$ip.' pushed '.$filename.' (path: '.$path.')') unless $c->config('quiet_logs'); # Give url to user $short = $record->short; @@ -562,7 +562,7 @@ sub short { if ($image->enabled && $image->path) { if($image->delete_at_day && $image->created_at + $image->delete_at_day * 86400 <= time()) { # Log deletion - $c->app->log->info('[DELETION] someone tried to view '.$image->filename.' but it has been removed by expiration (path: '.$image->path.')'); + $c->app->log->info('[DELETION] someone tried to view '.$image->filename.' but it has been removed by expiration (path: '.$image->path.')') unless $c->config('quiet_logs'); # Delete image $c->delete_image($image); @@ -608,7 +608,7 @@ sub short { # Delete image if needed if ($image->delete_at_first_view && $image->counter >= 1) { # Log deletion - $c->app->log->info('[DELETION] someone made '.$image->filename.' removed (path: '.$image->path.')'); + $c->app->log->info('[DELETION] someone made '.$image->filename.' removed (path: '.$image->path.')') unless $c->config('quiet_logs'); # Delete image $c->delete_image($image); @@ -626,7 +626,7 @@ sub short { # Update counter $c->on(finish => sub { # Log access - $c->app->log->info('[VIEW] someone viewed '.$image->filename.' (path: '.$image->path.')'); + $c->app->log->info('[VIEW] someone viewed '.$image->filename.' (path: '.$image->path.')') unless $c->config('quiet_logs'); # Update record if ($c->config('minion')->{enabled}) { @@ -638,7 +638,7 @@ sub short { # Delete image if needed if ($image->delete_at_first_view) { # Log deletion - $c->app->log->info('[DELETION] someone made '.$image->filename.' removed (path: '.$image->path.')'); + $c->app->log->info('[DELETION] someone made '.$image->filename.' removed (path: '.$image->path.')') unless $c->config('quiet_logs'); # Delete image $c->delete_image($image); @@ -647,7 +647,7 @@ sub short { } } elsif ($image->path && !$image->enabled) { # Log access try - $c->app->log->info('[NOT FOUND] someone tried to view '.$short.' but it does\'nt exist anymore.'); + $c->app->log->info('[NOT FOUND] someone tried to view '.$short.' but it does\'nt exist anymore.') unless $c->config('quiet_logs'); # Warn user $c->flash( @@ -688,7 +688,7 @@ sub zip { my $filename = $image->filename; if($image->delete_at_day && $image->created_at + $image->delete_at_day * 86400 <= time()) { # Log deletion - $c->app->log->info('[DELETION] someone tried to view '.$image->filename.' but it has been removed by expiration (path: '.$image->path.')'); + $c->app->log->info('[DELETION] someone tried to view '.$image->filename.' but it has been removed by expiration (path: '.$image->path.')') unless $c->config('quiet_logs'); # Delete image $c->delete_image($image); @@ -701,7 +701,7 @@ sub zip { # Delete image if needed if ($image->delete_at_first_view && $image->counter >= 1) { # Log deletion - $c->app->log->info('[DELETION] someone made '.$image->filename.' removed (path: '.$image->path.')'); + $c->app->log->info('[DELETION] someone made '.$image->filename.' removed (path: '.$image->path.')') unless $c->config('quiet_logs'); # Delete image $c->delete_image($image); @@ -728,7 +728,7 @@ sub zip { } # Log access - $c->app->log->info('[VIEW] someone viewed '.$image->filename.' (path: '.$image->path.')'); + $c->app->log->info('[VIEW] someone viewed '.$image->filename.' (path: '.$image->path.')') unless $c->config('quiet_logs'); # Update counter and record if ($c->config('minion')->{enabled}) { @@ -739,7 +739,7 @@ sub zip { } } elsif ($image->path && !$image->enabled) { # Log access try - $c->app->log->info('[NOT FOUND] someone tried to view '.$short.' but it does\'nt exist anymore.'); + $c->app->log->info('[NOT FOUND] someone tried to view '.$short.' but it does\'nt exist anymore.') unless $c->config('quiet_logs'); # Warn user $zip->addString(encode('UTF-8', $c->l('Unable to find the image: it has been deleted.')), 'images/'.$image->filename.'.txt'); diff --git a/lib/Mounter.pm b/lib/Mounter.pm index 32ef5d0..6ba1ad6 100644 --- a/lib/Mounter.pm +++ b/lib/Mounter.pm @@ -47,6 +47,7 @@ sub startup { db_path => 'minion.db' }, cache_max_size => 0, + quiet_logs => 0, } } ); diff --git a/lutim.conf.template b/lutim.conf.template index 0408d12..f033bd0 100644 --- a/lutim.conf.template +++ b/lutim.conf.template @@ -178,10 +178,19 @@ # maximum size (in MB) of memory allowed for the image cache # Lutim has a built-in memory-based image cache to accelerate responses to often-viewed images. # This setting makes the cache remove oldest viewed image if the cache size is over it. + # WARNING: a cache is created for each hypnotoad worker, which by default is twice the number of + # CPUs you have. See http://mojolicious.org/perldoc/Mojo/Server/Hypnotoad#workers for details + # So, if you have 4 workers and set cache_max_size to 100, the real maximum size of RAM used for + # cache is 400MB. # If set to 0, the cache is disabled # optional, default is 0 #cache_max_size => 0, + # enable or disable Lutim built-in logs + # set to 1 to disable logs + # optional, default is 0 + #quiet_logs => 0, + ########################## # Lutim cron jobs settings ##########################