mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-12-22 13:34:55 +01:00
repaires log clearence from analytics page
This commit is contained in:
parent
125bd07162
commit
955409d81a
4 changed files with 16 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -20,3 +20,4 @@ logs/
|
||||||
.devcontainer/cbpi-dev-config/*
|
.devcontainer/cbpi-dev-config/*
|
||||||
cbpi4-*
|
cbpi4-*
|
||||||
temp*
|
temp*
|
||||||
|
*.patch
|
6
.vscode/launch.json
vendored
6
.vscode/launch.json
vendored
|
@ -10,7 +10,11 @@
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"module": "run",
|
"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"
|
"preLaunchTask": "copy default cbpi config files if dev config files dont exist"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -152,6 +152,12 @@ class LogController:
|
||||||
def clear_log(self, name:str ) -> str:
|
def clear_log(self, name:str ) -> str:
|
||||||
all_filenames = glob.glob(os.path.join(self.logsFolderPath, f"sensor_{name}.log*"))
|
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:
|
for f in all_filenames:
|
||||||
try:
|
try:
|
||||||
os.remove(f)
|
os.remove(f)
|
||||||
|
|
|
@ -17,7 +17,6 @@ class SensorLogTargetCSV(CBPiExtension):
|
||||||
|
|
||||||
def __init__(self, cbpi): # called from cbpi on start
|
def __init__(self, cbpi): # called from cbpi on start
|
||||||
self.cbpi = cbpi
|
self.cbpi = cbpi
|
||||||
self.datalogger = {}
|
|
||||||
self.logfiles = self.cbpi.config.get("CSVLOGFILES", "Yes")
|
self.logfiles = self.cbpi.config.get("CSVLOGFILES", "Yes")
|
||||||
if self.logfiles == "No":
|
if self.logfiles == "No":
|
||||||
return # never run()
|
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.
|
# 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.
|
# but after initially enabling this logging target a restart is required.
|
||||||
return
|
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))
|
max_bytes = int(self.cbpi.config.get("SENSOR_LOG_MAX_BYTES", 100000))
|
||||||
backup_count = int(self.cbpi.config.get("SENSOR_LOG_BACKUP_COUNT", 3))
|
backup_count = int(self.cbpi.config.get("SENSOR_LOG_BACKUP_COUNT", 3))
|
||||||
|
|
||||||
|
@ -44,9 +43,9 @@ class SensorLogTargetCSV(CBPiExtension):
|
||||||
data_logger.setLevel(logging.DEBUG)
|
data_logger.setLevel(logging.DEBUG)
|
||||||
handler = RotatingFileHandler(os.path.join(self.cbpi.log.logsFolderPath, f"sensor_{id}.log"), maxBytes=max_bytes, backupCount=backup_count)
|
handler = RotatingFileHandler(os.path.join(self.cbpi.log.logsFolderPath, f"sensor_{id}.log"), maxBytes=max_bytes, backupCount=backup_count)
|
||||||
data_logger.addHandler(handler)
|
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):
|
def setup(cbpi):
|
||||||
cbpi.plugin.register("SensorLogTargetCSV", SensorLogTargetCSV)
|
cbpi.plugin.register("SensorLogTargetCSV", SensorLogTargetCSV)
|
||||||
|
|
Loading…
Reference in a new issue