Code quality: Use proper logging msg formatting

pull/7/head
Ferry Boender 8 years ago
parent d651ca8aa0
commit 0e923f49eb
  1. 4
      src/daemon.py
  2. 11
      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) # Fork a child and end parent (so init now owns process)
pid = os.fork() pid = os.fork()
if pid > 0: if pid > 0:
self.log.info("PID = {0}".format(pid)) self.log.info("PID = %s", (pid))
pidfile = file(self.pid_file, 'w') pidfile = file(self.pid_file, 'w')
pidfile.write(str(pid)) pidfile.write(str(pid))
pidfile.close() pidfile.close()
@ -165,7 +165,7 @@ class Daemon(object): # pragma: no cover
""" """
Remvoe pid files and call registered shutodnw callbacks. Remvoe pid files and call registered shutodnw callbacks.
""" """
self.log.info("Received signal {0}".format(sig)) self.log.info("Received signal %s", (sig))
if os.path.exists(self.pid_file): if os.path.exists(self.pid_file):
os.unlink(self.pid_file) os.unlink(self.pid_file)
self.shutdown_callback() self.shutdown_callback()

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

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

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

Loading…
Cancel
Save