The International Simutrans Forum

Development => Technical Documentation => Topic started by: jamespetts on May 11, 2014, 01:17:11 PM

Title: Logging
Post by: jamespetts on May 11, 2014, 01:17:11 PM
Is there any way of which anyone is aware to (1) customise the directory into which the Linux server build of Simutrans records its logs; and (2) require that the existing log file, if any, at that location is appended rather than overwritten? I am having trouble tracking down crashes on my server because the restart script causes the log file to be overwritten.
Title: Re: Logging
Post by: Ters on May 11, 2014, 02:16:19 PM
If you have a script that restarts the server, then I would recommend changing that script so that it renames the old log file first. That's a better solution than appending, as you can then open the old log in peace (it isn't written to it anymore) and find the last things that happened at the bottom (no need to search for it). As a bonus, you can also see how often and when it restarted.
Title: Re: Logging
Post by: jamespetts on May 11, 2014, 02:31:58 PM
Yes, I see - and presumably, the script would also need to rename the old log that it previously re-named, and so on ad infinitum...?
Title: Re: Logging
Post by: Ters on May 11, 2014, 03:26:25 PM
No, you give each log file a unique name. The easiest, and perhaps most popular way of doing that, is by including the current date and time in the file name.
Title: Re: Logging
Post by: jamespetts on May 11, 2014, 06:54:36 PM
Ahh, yes, I see. I have had a go at modifying the script to do this, although my shell scripting knowledge is limited, so I am not sure whether it will work.
Title: Re: Logging
Post by: Ters on May 11, 2014, 07:10:48 PM
Something like mv simu.log simu.log.`date +%FT%T` perhaps. %T means the file name will include colons. If this is a problem, a different format argument must be passed to date. See date --help for that.
Title: Re: Logging
Post by: jamespetts on May 11, 2014, 08:00:48 PM
What I have done is this:


now=$(date +"%d_m%_%Y")
/bin/sh -c "cp /usr/share/games/simutrans-experimental/simutrans/simu-server13353.log /var/log/old-log_$now.log"


Does this look workable to you?

Edit: Sadly, this does not seem to work, and it is not clear why.
Title: Re: Logging
Post by: An_dz on May 12, 2014, 03:43:27 AM
It is the m% which should be %m. now was receiving m%y. I would include _%T at now to include the time.
Title: Re: Logging
Post by: jamespetts on May 12, 2014, 09:35:20 AM
Quote from: An_dz on May 12, 2014, 03:43:27 AM
It is the m% which should be %m. now was receiving m%y. I would include _%T at now to include the time.

Ahh, splendid, thank you - modified accordingly.
Title: Re: Logging
Post by: Ashley on June 10, 2014, 09:40:01 AM
Best to build Simutrans with syslog support, and then manage your logs through that (most Linux systems come with logrotate or a derivative).
Title: Re: Logging
Post by: jamespetts on June 10, 2014, 09:51:36 AM
Hmm - how would one build Simutrans with syslog support...?
Title: Re: Logging
Post by: Ters on June 10, 2014, 02:18:47 PM
It's documented it config.template, which is the place for customizing the build (except MSVC builds, and possibly native MacOS).
Title: Re: Logging
Post by: Ashley on June 13, 2014, 11:30:14 AM
Yeah, it's in config.template:

FLAGS = -DSYSLOG
Title: Re: Logging
Post by: Ters on June 13, 2014, 02:27:27 PM
...although I did look in config.default first, and could not find it. Which makes perfect sense, since I only sync config.default from config.template on rare occasions. It's one of the tripwires when having templates in VCS that needs to be copied and configured for each workspace: the file you normally use is almost never up-to-date. But configuring the file that lies in VCS is more dangerous, if you have commit rights, just for everyone else but you.
Title: Re: Logging
Post by: jamespetts on June 13, 2014, 06:47:28 PM
Thank you very much for this: that is most helpful. I have now amended the config.default on my server to include this, so it should be incorporated into the next build.