kopia lustrzana https://github.com/hholzgra/maposmatic/
Switch to a better logging facility
We now have separate logging for the web service (logwww) and the daemon (logdaemon). They can be configured separately in the settings_local.py file.stable
rodzic
5a38ca6107
commit
331d738c89
|
@ -5,7 +5,7 @@ import time, os , sys, select, signal
|
|||
from datetime import datetime
|
||||
|
||||
from www.maposmatic.models import MapRenderingJob
|
||||
from www.settings import RENDERING_RESULT_PATH
|
||||
from www.settings import RENDERING_RESULT_PATH, logdaemon
|
||||
import ocitysmap
|
||||
|
||||
def handler(signum, frame, pipe_write):
|
||||
|
@ -34,7 +34,7 @@ def render_job_process(job):
|
|||
sys.exit(0)
|
||||
|
||||
def render_job(job):
|
||||
print 'Rendering "%s"...' % job.maptitle
|
||||
logdaemon.info("[job %d] starting rendering, title '%s'" % (job.id, job.maptitle))
|
||||
job.start_rendering()
|
||||
(pipe_read, pipe_write) = os.pipe()
|
||||
signal.signal(signal.SIGCHLD,
|
||||
|
@ -51,7 +51,9 @@ def render_job(job):
|
|||
os.kill(pid, signal.SIGTERM)
|
||||
time.sleep(2)
|
||||
os.kill(pid, signal.SIGKILL)
|
||||
job.end_rendering("rendering took too long, killed")
|
||||
resultmsg = "rendering took too long, killed"
|
||||
logdaemon.info("[job %d] %s" % (job.id, resultmsg))
|
||||
job.end_rendering(resultmsg)
|
||||
return
|
||||
finally:
|
||||
print "end of process %d" % pid
|
||||
|
@ -65,14 +67,17 @@ def render_job(job):
|
|||
resultmsg = "rendering failed with %d" % error_code
|
||||
elif os.WIFSIGNALED(status):
|
||||
resultmsg = "rendering killed by signal %d" % os.WTERMSIG(status)
|
||||
logdaemon.info("[job %d] %s" % (job.id, resultmsg))
|
||||
job.end_rendering(resultmsg)
|
||||
return
|
||||
|
||||
if not os.path.isdir(RENDERING_RESULT_PATH):
|
||||
print "ERROR: please set RENDERING_RESULT_PATH ('%s') to an existing directory" % \
|
||||
RENDERING_RESULT_PATH
|
||||
logdaemon.error("ERROR: please set RENDERING_RESULT_PATH ('%s') to an existing directory" % \
|
||||
RENDERING_RESULT_PATH)
|
||||
sys.exit(1)
|
||||
|
||||
logdaemon.info("started")
|
||||
|
||||
while True:
|
||||
jobs = MapRenderingJob.objects.to_render()
|
||||
if not jobs:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# Django settings for www project.
|
||||
|
||||
import logging
|
||||
from settings_local import *
|
||||
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
@ -68,3 +69,17 @@ LOCAL_MEDIA_PATH = os.path.join(PROJECT_PATH, 'media')
|
|||
INSTALLED_APPS = (
|
||||
'www.maposmatic',
|
||||
)
|
||||
|
||||
formatter = logging.Formatter("%(name)s - %(asctime)s - %(levelname)s - %(message)s")
|
||||
|
||||
logwww = logging.getLogger("maposmatic-www")
|
||||
logwww.setLevel(WWW_LOGLEVEL)
|
||||
fh = logging.FileHandler(WWW_LOGFILE)
|
||||
fh.setFormatter(formatter)
|
||||
logwww.addHandler(fh)
|
||||
|
||||
logdaemon = logging.getLogger("maposmaticd")
|
||||
logdaemon.setLevel(DAEMON_LOGLEVEL)
|
||||
fh = logging.FileHandler(DAEMON_LOGFILE)
|
||||
fh.setFormatter(formatter)
|
||||
logdaemon.addHandler(fh)
|
||||
|
|
|
@ -14,3 +14,9 @@ DATABASE_PORT = '' # Set to empty string for default. Not used with
|
|||
|
||||
RENDERING_RESULT_PATH = '/tmp/direc/tory'
|
||||
RENDERING_RESULT_URL = 'http://host.name/dir/ec/tory'
|
||||
|
||||
WWW_LOGFILE = '/tmp/maposmatic-www.log'
|
||||
WWW_LOGLEVEL = logging.INFO
|
||||
|
||||
DAEMON_LOGFILE = '/tmp/maposmaticd.log'
|
||||
DAEMON_LOGLEVEL = logging.INFO
|
||||
|
|
Ładowanie…
Reference in New Issue