Code quality: logging

pull/7/head
Ferry Boender 8 years ago
parent 0e923f49eb
commit 34365b696c
  1. 4
      src/daemon.py
  2. 12
      src/runscript.py
  3. 2
      src/scriptform.py
  4. 8
      src/webapp.py

@ -136,7 +136,7 @@ class Daemon(object): # pragma: no cover
# Fork a child and end parent (so init now owns process)
pid = os.fork()
if pid > 0:
self.log.info("PID = %s", (pid))
self.log.info("PID = %s", pid)
pidfile = file(self.pid_file, 'w')
pidfile.write(str(pid))
pidfile.close()
@ -165,7 +165,7 @@ class Daemon(object): # pragma: no cover
"""
Remvoe pid files and call registered shutodnw callbacks.
"""
self.log.info("Received signal %s", (sig))
self.log.info("Received signal %s", sig)
if os.path.exists(self.pid_file):
os.unlink(self.pid_file)
self.shutdown_callback()

@ -61,14 +61,14 @@ def run_script(form_def, form_values, stdout=None, stderr=None):
]
msg = "Running script as user={0}, gid={1}, groups={2}"
run_as_fn = run_as(runas_pw.pw_uid, runas_pw.pw_gid, groups)
log.info("%s", (msg.format(runas_pw.pw_name,
runas_gr.gr_name,
str(groups))))
log.info("%s", msg.format(runas_pw.pw_name,
runas_gr.gr_name,
str(groups)))
else:
run_as_fn = None
if form_def.run_as is not None:
log.critical("Not running as root, so we can't run the "
"script as user '%s'", (form_def.run_as))
"script as user '%s'", form_def.run_as)
# If the form output type is 'raw', we directly stream the output to
# the browser. Otherwise we store it for later displaying.
@ -82,7 +82,7 @@ def run_script(form_def, form_values, stdout=None, stderr=None):
close_fds=True,
preexec_fn=run_as_fn)
stdout, stderr = proc.communicate(input)
log.info("Exit code: %s", (proc.returncode))
log.info("Exit code: %s", proc.returncode)
return proc.returncode
except OSError as err:
log.exception(err)
@ -99,7 +99,7 @@ def run_script(form_def, form_values, stdout=None, stderr=None):
close_fds=True,
preexec_fn=run_as_fn)
stdout, stderr = proc.communicate()
log.info("Exit code: %s", (proc.returncode))
log.info("Exit code: %s", proc.returncode)
return {
'stdout': stdout,
'stderr': stderr,

@ -139,7 +139,7 @@ class ScriptForm(object):
self.httpd = ThreadedHTTPServer((listen_addr, listen_port),
ScriptFormWebApp)
self.httpd.daemon_threads = True
self.log.info("Listening on %s:%s", (listen_addr, listen_port))
self.log.info("Listening on %s:%s", listen_addr, listen_port)
self.running = True
self.httpd.serve_forever()
self.running = False

@ -413,10 +413,10 @@ class ScriptFormWebApp(RequestHandler):
# Log the callback and its parameters for auditing purposes.
log = logging.getLogger('CALLBACK_AUDIT')
cwd = os.path.realpath(os.curdir)
log.info("Calling script: %s", (form_def.script))
log.info("Current working dir: %s", (cwd))
log.info("User: %s", (username))
log.info("Variables: %s", (dict(form_values.items())))
log.info("Calling script: %s", form_def.script)
log.info("Current working dir: %s", cwd)
log.info("User: %s", username)
log.info("Variables: %s", dict(form_values.items()))
form_def = form_config.get_form_def(form_name)
result = runscript.run_script(form_def, form_values, self.wfile,

Loading…
Cancel
Save