Skip to content

Commit

Permalink
Merge pull request PanDAWMS#3 from PanDAWMS/escape_json
Browse files Browse the repository at this point in the history
Message body needs to be json
  • Loading branch information
fbarreir committed Nov 30, 2015
2 parents 1b2e7bb + 7ccd205 commit b5fd6c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions pandacommon/pandalogger/PandaLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def run(self):
h.putrequest(self.method, url)
if self.method == "POST":
h.putheader("Content-length", str(len(self.data)))
h.endheaders()
if self.method == "POST":
h.putheader ("Content-type", "application/json; charset=UTF-8")
h.endheaders()
h.send(self.data)
response = h.getresponse() # can't do anything with the result
#for s in self.getData(response, 1024):
Expand Down Expand Up @@ -115,7 +115,7 @@ def mapLogRecord(self, record):
"""
Default implementation of mapping the log record into a dict
that is sent as the CGI data. Overwrite in your class.
Contributed by Franz Glasner.
Contributed by Franz Glasner.
"""
newrec = record.__dict__
for p in self.params:
Expand Down Expand Up @@ -143,9 +143,10 @@ def emit(self, record):
# The new logger needs to be json encoded and use POST method

if self.encoding == JSON:

arr=[{
"headers":{"timestamp" : int(time.time())*1000, "host" : "%s:%s"%(self.url, self.port)},
"body": "%s"%self.mapLogRecord(record)
"body": "{0}".format(json.dumps(self.mapLogRecord(record)))
}]
data = json.dumps(arr)
else:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def run (self):
# remove build/*/dump for bdist
patt = re.sub('build/[^/]+/dumb','',patt)
# remove /var/tmp/*-buildroot for bdist_rpm
patt = re.sub('/var/tmp/.*-buildroot','',patt)
patt = re.sub('/var/tmp/.*-buildroot','',patt)
# replace
filedata = filedata.replace('@@%s@@' % item, patt)
# write to dest
Expand Down Expand Up @@ -99,6 +99,7 @@ def run (self):
'pandacommon.liveconfigparser',
'pandacommon.pandalogger',
'pandacommon.pandautils',
'pandacommon.test',
],
data_files=[
('/etc/panda',
Expand Down

0 comments on commit b5fd6c2

Please sign in to comment.