TurboGears log files and log rotation

The error log is rotated weekly on Sunday. 4 backups are saved.

The access log is not stored since it would be a duplicate of the
Apache logs. It can be enabled if desired.

Had to move the call to daemonize() in ipa-webgui so that the
fork is done before TurboGears is initialized. Otherwise the log
files end up getting closed.
This commit is contained in:
Rob Crittenden
2007-11-01 11:55:53 -04:00
parent d9f809746b
commit a51dd58278
2 changed files with 29 additions and 16 deletions

View File

@@ -20,14 +20,24 @@
import os, sys
def daemonize():
pid = os.fork()
# fork once so the parent can exit
try:
pid = os.fork()
except OSError, e:
raise Exception, "%s [%d]" % (e.strerror, e.errno)
if pid != 0:
os._exit(0)
# become session leader
os.setsid()
# fork again to reparent to init
pid = os.fork()
try:
pid = os.fork()
except OSError, e:
raise Exception, "%s [%d]" % (e.strerror, e.errno)
if pid != 0:
os._exit(0)
@@ -60,6 +70,13 @@ devel = False
if os.path.exists(os.path.join(os.path.dirname(__file__), "Makefile.am")):
devel = True
if not devel:
try:
daemonize()
except Exception, e:
sys.stderr.write("error becoming daemon: " + str(e))
sys.exit(1)
sys.path.append("/usr/share/ipa/")
# this must be after sys.path is changed to work correctly
@@ -83,16 +100,4 @@ else:
from ipagui.controllers import Root
if not devel:
try:
daemonize()
except Exception, e:
sys.stderr.write("error becoming daemon: " + str(e))
sys.exit(1)
start_server(Root())

View File

@@ -64,12 +64,20 @@ format='*(asctime)s *(name)s *(levelname)s *(message)s'
[[handlers]]
[[[debug_out]]]
class='StreamHandler'
# Rotate weekly on Sunday. Keep 4 backups of the log
class='TimedRotatingFileHandler'
level='DEBUG'
args='(sys.stdout,)'
args="('/var/log/ipa_error.log', 'w6', 1, 4)"
formatter='full_content'
[[[access_out]]]
# For example only if one wants to duplicate the access log in TurboGears
# Rotate weekly on Sunday. Keep 4 backups of the log
#class='TimedRotatingFileHandler'
#level='INFO'
#args="('/var/log/ipa_error.log', 'w6', 1, 4)"
#formatter='message_only'
# By default log access to stdout which will go to /dev/null in production
class='StreamHandler'
level='INFO'
args='(sys.stdout,)'