loguru
loguru copied to clipboard
Log file accumulating the same message repeatedly
I am wondering what might be causing my log file to be accumulating the same message repeatedly, like below:
2021-03-14 20:11:05.893 | INFO | __main__:train_and_evaluate:47 - Training model RTE on this checkpoint: bert-base-uncased
2021-03-14 20:11:05.893 | INFO | __main__:train_and_evaluate:47 - Training model RTE on this checkpoint: bert-base-uncased
2021-03-14 20:11:05.893 | INFO | __main__:train_and_evaluate:47 - Training model RTE on this checkpoint: bert-base-uncased
2021-03-14 20:11:05.893 | INFO | __main__:train_and_evaluate:47 - Training model RTE on this checkpoint: bert-base-uncased
.... (many more times)
2021-03-14 20:11:12.446 | INFO | __main__:train_and_evaluate:104 - Device: CUDA
.... (many more times -- you get the picture)
My training process uses a handful of files where the logger is instantiated like so in __main__.py:
# initialize logging
logger.add(log_path + '\\' + args.model + '.log', rotation="10 MB")
logger.info(f"Training model {args.model} on this checkpoint: {args.checkpoint}")
logger is then passed around to subsequent functions, contained in different .py files as the training cycle progresses (e.g., a trainer, an evaluator, etc). I am wondering if that is potentially a culprit?
Are you possibly using multiprocessing or any library spawning child processes ? It could cause part of your script to be executed multiple times. Maybe try to guard the logger initialization inside an if __name__ == "__main__": block.
Are you possibly using
multiprocessingor any library spawning child processes ? It could cause part of your script to be executed multiple times. Maybe try to guard theloggerinitialization inside anif __name__ == "__main__":block.
Thanks for your insights! I will try giving it a rework!