Skip to content

Commit 2e88d22

Browse files
authored
Log rotation (#308)
* Merged main with the location changes * no ubx yet * Revert "no ubx yet" This reverts commit c872394. * Let the logger do the rollover * Ecef fix (#307) * Merged main with the location changes * no ubx yet * Revert "no ubx yet" This reverts commit c872394. * fix ecef errors no ubx yet Revert "no ubx yet" This reverts commit c872394. Let the logger do the rollover
1 parent 7352e33 commit 2e88d22

2 files changed

Lines changed: 5 additions & 29 deletions

File tree

python/PiFinder/main.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -764,38 +764,12 @@ def main(
764764
exit()
765765

766766

767-
def rotate_logs() -> Path:
768-
"""
769-
Rotates log files, returns the log file to use
770-
"""
771-
log_index = list(range(5))
772-
log_index.reverse()
773-
for i in log_index:
774-
try:
775-
shutil.copyfile(
776-
utils.data_dir / f"pifinder.{i}.log",
777-
utils.data_dir / f"pifinder.{i+1}.log",
778-
)
779-
except FileNotFoundError:
780-
pass
781-
782-
try:
783-
shutil.move(
784-
utils.data_dir / "pifinder.log",
785-
utils.data_dir / "pifinder.0.log",
786-
)
787-
except FileNotFoundError:
788-
pass
789-
790-
return utils.data_dir / "pifinder.log"
791-
792-
793767
if __name__ == "__main__":
794768
print("Bootstrap logging configuration ...")
795769
logging.basicConfig(format="%(asctime)s BASIC %(name)s: %(levelname)s %(message)s")
796770
rlogger = logging.getLogger()
797771
rlogger.setLevel(logging.INFO)
798-
log_path = rotate_logs()
772+
log_path = utils.data_dir / "pifinder.log"
799773
try:
800774
log_helper = MultiprocLogging(
801775
Path("pifinder_logconf.json"),

python/PiFinder/multiproclogging.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ def _run_sink(self, output: Path, queues: List[Queue]):
121121
for hdlr in hdlrs:
122122
rLogger.removeHandler(hdlr)
123123

124-
# configure logging to store everything in output
125-
h = logging.handlers.WatchedFileHandler(output)
124+
# Set maxBytes to 50MB (50 * 1024 * 1024 bytes) and keep 5 backup files
125+
h = logging.handlers.RotatingFileHandler(
126+
output, maxBytes=50*1024*1024, backupCount=5, encoding='utf-8'
127+
)
126128
f = logging.Formatter(self._formatter)
127129
h.setFormatter(f)
128130
rLogger.addHandler(h)

0 commit comments

Comments
 (0)