repaires log clearence from analytics page

This commit is contained in:
prash3r 2023-05-16 12:23:24 +02:00
parent 125bd07162
commit 955409d81a
4 changed files with 16 additions and 6 deletions

3
.gitignore vendored
View file

@ -19,4 +19,5 @@ logs/
.coverage
.devcontainer/cbpi-dev-config/*
cbpi4-*
temp*
temp*
*.patch

6
.vscode/launch.json vendored
View file

@ -10,7 +10,11 @@
"type": "python",
"request": "launch",
"module": "run",
"args": ["--config-folder-path=./.devcontainer/cbpi-dev-config", "start"],
"args": [
"--config-folder-path=./.devcontainer/cbpi-dev-config",
"--debug-log-level=20",
"start"
],
"preLaunchTask": "copy default cbpi config files if dev config files dont exist"
},

View file

@ -151,6 +151,12 @@ class LogController:
def clear_log(self, name:str ) -> str:
all_filenames = glob.glob(os.path.join(self.logsFolderPath, f"sensor_{name}.log*"))
logging.info(f'Deleting logfiles for sensor {name}.')
if name in self.datalogger:
self.datalogger[name].removeHandler(self.datalogger[name].handlers[0])
del self.datalogger[name]
for f in all_filenames:
try:

View file

@ -17,7 +17,6 @@ class SensorLogTargetCSV(CBPiExtension):
def __init__(self, cbpi): # called from cbpi on start
self.cbpi = cbpi
self.datalogger = {}
self.logfiles = self.cbpi.config.get("CSVLOGFILES", "Yes")
if self.logfiles == "No":
return # never run()
@ -35,7 +34,7 @@ class SensorLogTargetCSV(CBPiExtension):
# as long as cbpi was STARTED with CSVLOGFILES set to Yes this function is still subscribed, so changes can be made on the fly.
# but after initially enabling this logging target a restart is required.
return
if id not in self.datalogger:
if id not in self.cbpi.log.datalogger:
max_bytes = int(self.cbpi.config.get("SENSOR_LOG_MAX_BYTES", 100000))
backup_count = int(self.cbpi.config.get("SENSOR_LOG_BACKUP_COUNT", 3))
@ -44,9 +43,9 @@ class SensorLogTargetCSV(CBPiExtension):
data_logger.setLevel(logging.DEBUG)
handler = RotatingFileHandler(os.path.join(self.cbpi.log.logsFolderPath, f"sensor_{id}.log"), maxBytes=max_bytes, backupCount=backup_count)
data_logger.addHandler(handler)
self.datalogger[id] = data_logger
self.cbpi.log.datalogger[id] = data_logger
self.datalogger[id].info("%s,%s" % (formatted_time, str(value)))
self.cbpi.log.datalogger[id].info("%s,%s" % (formatted_time, str(value)))
def setup(cbpi):
cbpi.plugin.register("SensorLogTargetCSV", SensorLogTargetCSV)