Bug 1943 - Rotating SlimServer logs
: Rotating SlimServer logs
Status: CLOSED FIXED
Product: Logitech Media Server
Classification: Unclassified
Component: Tools
: unspecified
: PC All
: P2 enhancement with 1 vote (vote)
: Future
Assigned To: Unassigned bug - please assign me!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-08-07 19:26 UTC by Jim McAtee
Modified: 2009-09-08 09:13 UTC (History)
3 users (show)

See Also:
Category: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jim McAtee 2005-08-07 19:26:34 UTC
I run SlimServer with logging enabled to help with whatever beta debugging I 
can.  It's been very stable lately, but will crash on the rare occasion.  The 
log file commonly grows to 1/2 GByte or more without my noticing.  Then when 
there's a crash, I have to deal with opening an enormous file.  And if I do 
notice that the log has grown to enormous proportions, I can't delete it 
without first shutting down SlimServer.

Create a logging preference to designate the directory where SlimServer logs 
are written, then optionally rotate the logs daily using something like a yy-mm-
dd.log naming convention.
Comment 1 Blackketter Dean 2005-08-08 14:43:46 UTC
Jim: What OS are you running on?
Comment 2 Jim McAtee 2005-08-08 18:40:22 UTC
Currently it's XP Pro.  I realize I could script something, but if I'm not 
mistaken it would require stopping and restarting the SlimServer service.
Comment 3 Simon Turner 2008-01-12 00:10:37 UTC
My SC7 Windows scanner log has just grown to 1gb... my server log to 0.25gb, causing Windows to report disk full alerts.
Wouldn't it be best if the scanner log file was deleted and recreated afresh when a full wipe and rescan was performed?
Logging is enabled by default isn't it, so this growth will become a problem over time for many users with large libraries? I certainly don't remember adjusting any logging preferences since my last complete reinstall three weeks ago.
Comment 4 Jim McAtee 2008-01-12 00:35:07 UTC
(In reply to comment #3)
> My SC7 Windows scanner log has just grown to 1gb... my server log to 0.25gb,
> causing Windows to report disk full alerts.

The new default logging levels should prevent this, with everything now set to the 'Error' level (with the exception of server.memory set to Off).  If you've been testing SC7 betas since before the change was made to the default levels, you can either stop the server and delete the log.conf file or else go down the list and manually set them all to Error.
Comment 5 Michael Herger 2008-10-24 06:30:50 UTC
I think we should have some simple form of rotation for systems which don't do this automatically. At least at startup check the disk space and log file size. If it's bigger than some threshold, rename it, create new one. Next time delete the old one before renaming the current etc.

Could really be very simple. But seeing users' Windows crash because our logs are GBs large is bad.

if size(log) > 100MB {
   if -e log.0 delete log.0
   move log log.0
   touch log
}
Comment 6 Michael Herger 2008-10-27 01:43:28 UTC
Triode - where in the log code would log rotation best be called? I think we don't need full featured rotation (as provided by eg. Log::Log4perl::JavaMap::RollingFileAppender, but just make sure our logs don't grow endlessly. I could imagine checking file sizes eg. during S::U::Log->init at startup. 
Comment 7 Michael Herger 2008-10-27 01:44:36 UTC
Check all *.log files in a given folder for their size. Move to *.log.0 if too big:

sub logRotate {
	my $class   = shift;
	my $dir     = shift || Slim::Utils::OSDetect::dirsFor('log');

	opendir(DIR, $dir) or return;

	while ( defined (my $file = readdir(DIR)) ) {

		next if $file !~ /\.log$/;
		
		$file = catdir($dir, $file);
		
		my $oldfile = "$file.0";

		# max. log size 10MB
		if (-s $file > 1024 * 1024 * 10) {
			unlink $oldfile if -e $oldfile;
			move($file, "$file.0");
		}
	}
	
	closedir(DIR);
}
Comment 8 Adrian Smith 2008-10-27 13:23:08 UTC
Michael - if you are only doing it at startup then I would call this from S::U::Log->init but only call it if we are the server and not in scanner.pl.

This will require users to reboot their machines or start/stop the app occasionally but I suspect this is a viable compromise. 
Comment 9 Jim McAtee 2008-10-27 13:48:45 UTC
How about some minimal configuration ability?  No ui necessary, just a setting in server.prefs.  A single pref could control whether logs are rotated at all and what the max size in MB should be.  0 = don't rotate, 1 = 1 MB, 1024 = 1GB, etc.

Is there a single entry point for all of SC's logging?  You could effect a compromise between the overhead required to check the file size every time vs. allowing the file to grow indefinitely by keeping a counter and checking the file size every, say, 1000 logging entries.
Comment 10 Michael Herger 2008-10-27 23:40:29 UTC
change 23709 - add poor man's log rotation (Windows/OSX only)
- if log file size > 100MB move to *.log.1, create new file
- one old copy is kept on disc
- run during log initialization only, which means the log can still grow >100MB if SC isn't restarted

Jim - I understand your idea about using prefs to configure this. But I really don't like the idea of one more pref, and even less without UI. 

I've implemented the log rotation in Slim::Utils::OS. This means you could always change its behaviour by creating your own Slim::Utils::OS::Custom module. This module isn't overwritten during installation.

http://wiki.slimdevices.com/index.php/Customizing_SqueezeCenter_using_Slim::Utils::OS::Custom

Thanks!
Comment 11 James Richardson 2008-12-15 13:06:55 UTC
This bug appears to have been fixed in the latest release!

If you are still experiencing this problem, feel free to reopen the bug with your new comments and we'll have another look.

Make sure to include the version number of the software you are seeing the error with.