Skip to content

Commit

Permalink
fix list and unix timestamp. fixes mknx#211
Browse files Browse the repository at this point in the history
  • Loading branch information
kr2 committed May 9, 2017
1 parent 506af85 commit 24623dc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions plugins/datalog/__init__.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,29 @@ class DataLog():
_buffer_lock = None

def __init__(self, smarthome, path="var/log/data", filepatterns={ "default" : "{log}-{year}-{month}-{day}.csv" }, logpatterns={ "csv" : "{time};{item};{value}\n" }, cycle=10):

self._sh = smarthome
self.path = path

if type(filepatterns) is str:
filepatterns = [filepatterns]
if type(filepatterns) is list:
for pattern in filepatterns:
key, value = pattern.split(':')
self.filepatterns[key] = value
else:
self.filepatterns = filepatterns

if type(logpatterns) is str:
logpatterns = [logpatterns]
if type(logpatterns) is list:
newlogpatterns = {}
for pattern in logpatterns:
key, value = pattern.split(':')
newlogpatterns[key] = value
logpatterns = newlogpatterns


for log in self.filepatterns:
ext = self.filepatterns[log].split('.')[-1]
if ext in logpatterns:
Expand All @@ -61,7 +67,7 @@ def __init__(self, smarthome, path="var/log/data", filepatterns={ "default" : "{
self._items = {}
self._buffer = {}
self._buffer_lock = threading.Lock()

logger.info('DataLog: Initialized, logging to "{}"'.format(self.path))
for log in self.filepatterns:
logger.info('DataLog: Registered log "{}", file="{}", format="{}"'.format(log, self.filepatterns[log], self.logpatterns[log]))
Expand Down Expand Up @@ -136,7 +142,7 @@ def _dump(self):
handles[filename] = open(self.path + '/' + filename, 'a')

data = entry
data['stamp'] = data['time'].time();
data['stamp'] = data['time'].timestamp()
handles[filename].write(logpattern.format(**data))

except Exception as e:
Expand Down

0 comments on commit 24623dc

Please sign in to comment.