improved logging
This commit is contained in:
parent
66355c1f60
commit
54464620e2
|
@ -94,8 +94,8 @@ class PyExec():
|
|||
except Exception as exc:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||
self.logger.debug(exc_type, fname, exc_tb.tb_lineno)
|
||||
self.logger.error(str(exc))
|
||||
self.logger.debug("%s %s %s", exc_type, fname, exc_tb.tb_lineno)
|
||||
self.logger.error("%s", str(exc))
|
||||
return { "status" : "FAILED", "output" : { "message" : str(exc) }, "logs" : ["one","two"]}
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[common]
|
||||
loglevel = info
|
||||
loglevel = debug
|
||||
server = http://conductor-dev.int.d4science.net/api
|
||||
#server = http://localhost:8080/api
|
||||
threads = 1
|
||||
|
|
|
@ -102,7 +102,7 @@ class Ansible(PyExecPlugin):
|
|||
# create data structure that represents our play
|
||||
play_sources = loader.load(self.playbook)
|
||||
for play_source in play_sources:
|
||||
logging.debug("Executing playsource:",play_source)
|
||||
logging.getLogger("pyexec").debug("Executing playsource: %s",play_source)
|
||||
play_source["gather_facts"] = self.gather_facts
|
||||
# Create play object, playbook objects use .load instead of init or new methods,
|
||||
# this will also automatically create the task objects from the info provided in play_source
|
||||
|
|
|
@ -27,11 +27,15 @@ class Plugin(PyExecPlugin):
|
|||
self.fail = data.get("fail")
|
||||
|
||||
def doRequest(self):
|
||||
logging.debug(self.method, self.url, self.contenttype, self.accept)
|
||||
#logging.getLogger("pyexec").debug("%s - %s - %s - %s",self.method, self.url, self.contenttype, self.accept)
|
||||
if self.contenttype != None and self.contenttype.find("json") != -1:
|
||||
self.response = requests.request(self.method, self.url, headers=self.headers, json = self.body)
|
||||
self.request = requests.Request(self.method, self.url, headers=self.headers, json = self.body)
|
||||
else:
|
||||
self.response = requests.request(self.method, self.url, headers=self.headers, data = self.body, params = self.params)
|
||||
self.request = requests.Request(self.method, self.url, headers=self.headers, data = self.body, params = self.params)
|
||||
|
||||
self.request = self.request.prepare()
|
||||
logging.getLogger("pyexec").debug("%s url=%s body=%s",self.method, self.request.url,self.body)
|
||||
self.response = requests.Session().send(self.request)
|
||||
return self.response
|
||||
|
||||
def computeStatus(self):
|
||||
|
@ -49,16 +53,16 @@ class Plugin(PyExecPlugin):
|
|||
hdrs = {}
|
||||
for k in self.response.headers.keys(): hdrs[k] = self.response.headers[k]
|
||||
|
||||
logging.info("Response: {} {}".format(self.response.status_code, self.response.reason))
|
||||
logging.getLogger("pyexec").info("Response: {} {}".format(self.response.status_code, self.response.reason))
|
||||
|
||||
if hdrs.get("Content-Type") != None and hdrs["Content-Type"].find("json") != -1 or self.accept != None and self.accept.find("json") != -1:
|
||||
outbody = self.response.json() if len(self.response.content) != 0 else None
|
||||
else:
|
||||
outbody = self.response.text
|
||||
|
||||
logging.debug(outbody)
|
||||
logging.getLogger("pyexec").debug("%s", outbody)
|
||||
if status == "FAILED":
|
||||
raise("HTTP call failed with status {} ({}) - {}".format(self.response.status_code, self.response.reson, str(outbody)))
|
||||
raise Exception("HTTP call failed with status {} ({}) - {}".format(self.response.status_code, self.response.reason, str(outbody)))
|
||||
return {
|
||||
"body" : outbody,
|
||||
"headers" : hdrs,
|
||||
|
|
|
@ -28,7 +28,7 @@ class Plugin(PyExecPlugin):
|
|||
continue
|
||||
else:
|
||||
cmd = cmd.split() if not withshell else cmd
|
||||
logging.debug("Going to execute (withshell=%b) %s", withshell, cmd)
|
||||
logging.getLogger("pyexec").debug("Going to execute (withshell=%b) %s", withshell, cmd)
|
||||
try:
|
||||
completed = subprocess.run(cmd, shell=withshell, capture_output=True, text=True)
|
||||
except Exception as e:
|
||||
|
|
Loading…
Reference in New Issue