From e496648978bf287d3a06459e0ba810acf0aa3c4e Mon Sep 17 00:00:00 2001 From: Jeff Kunzelman Date: Sun, 5 Jan 2014 10:20:04 -0700 Subject: [PATCH 1/2] added log.py logging plugin. This plugin was created with the intention of logging sensor data to splunk. File is in json format with unit names omited. --- outputs.cfg | 3 +++ outputs/log.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 outputs/log.py diff --git a/outputs.cfg b/outputs.cfg index 6326dba..8b8c4e8 100644 --- a/outputs.cfg +++ b/outputs.cfg @@ -1,6 +1,9 @@ [Print] filename=print enabled=on +[Log] +filename=log +enabled=on [Xively] filename=xively diff --git a/outputs/log.py b/outputs/log.py new file mode 100644 index 0000000..1ecc3d4 --- /dev/null +++ b/outputs/log.py @@ -0,0 +1,23 @@ +import output +import datetime + +class Log(output.Output): + requiredData = [] + optionalData = [] + def __init__(self,data): + pass + def outputData(self,dataPoints): + f = open('sensors.log', 'a') + logline = '{"time":"' + logline += str(datetime.datetime.now()) + logline += '",' + for i in dataPoints: + logline += '"' + i["name"] + '"' + ":" + '"' + str(i["value"]) + '",' + + logline += "}\n" + + print(logline) + f.write(logline) + f.close() + + return True From 9dec4d1f5803c7eee0eeaf2a437587c559477c1e Mon Sep 17 00:00:00 2001 From: Jeff Kunzelman Date: Mon, 6 Jan 2014 11:16:25 -0700 Subject: [PATCH 2/2] Remove extra comma --- outputs/log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outputs/log.py b/outputs/log.py index 1ecc3d4..697186b 100644 --- a/outputs/log.py +++ b/outputs/log.py @@ -12,7 +12,7 @@ def outputData(self,dataPoints): logline += str(datetime.datetime.now()) logline += '",' for i in dataPoints: - logline += '"' + i["name"] + '"' + ":" + '"' + str(i["value"]) + '",' + logline += '"' + i["name"] + '"' + ":" + '"' + str(i["value"]) + '"' logline += "}\n"