Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smaller Log files by truncation #84

Open
wants to merge 1 commit into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+15 −11
Diff settings

Always

Just for now

remove last line if same as new line

  • Loading branch information...
carlallen committed Jul 15, 2017
commit 118cda5f79c36776887a8a7db4d59447cc548541
Copy path View file
@@ -18,6 +18,7 @@

import time
import uuid
from os import popen, system


class NotificationAPI(object):
@@ -84,7 +85,7 @@ class SensorAPI(object):
def init_sensors(self):
'''
Initialize all sensors
:return:
:return:
'''

self.app.logger.info("Init Sensors")
@@ -109,15 +110,15 @@ def stop_sensor(self, id):
def init_sensor(self, id):
'''
initialize sensor by id
:param id:
:return:
:param id:
:return:
'''

def start_active_sensor(instance):
'''
start active sensors as background job
:param instance:
:return:
:param instance:
:return:
'''
instance.execute()

@@ -152,6 +153,9 @@ def save_to_file(self, id, value, prefix="sensor"):
filename = "./logs/%s_%s.log" % (prefix, str(id))
formatted_time = strftime("%Y-%m-%d %H:%M:%S", localtime())
msg = str(formatted_time) + "," +str(value) + "\n"
if popen("tail -n 2 "+ filename).read().count(","+ str(value)+ "\n") == 2:
# if the data was logged twice, delete the last logged data and write a new one
system("truncate -s -\"$(tail -n1 " + filename + " | wc -c)\" " + filename)

with open(filename, "a") as file:
file.write(msg)
@@ -448,7 +452,7 @@ def init_kettle(self, id):
def run_init(self):
'''
call all initialziers after startup
:return:
:return:
'''
self.app.logger.info("Invoke Init")
self.cache["init"] = sorted(self.cache["init"], key=lambda k: k['order'])
@@ -462,10 +466,10 @@ def backgroundtask(self, key, interval, config_parameter=None):

'''
Background Task Decorator
:param key:
:param interval:
:param config_parameter:
:return:
:param key:
:param interval:
:param config_parameter:
:return:
'''
def real_decorator(function):
self.cache["background"].append({"function": function, "key": key, "interval": interval, "config_parameter": config_parameter})
@@ -477,7 +481,7 @@ def wrapper(*args, **kwargs):
def run_background_processes(self):
'''
call all background task after startup
:return:
:return:
'''
self.app.logger.info("Start Background")

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.