loguru icon indicating copy to clipboard operation
loguru copied to clipboard

Log file accumulating the same message repeatedly

Open afogarty85 opened this issue 4 years ago • 2 comments

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?

afogarty85 avatar Mar 16 '21 00:03 afogarty85

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.

Delgan avatar Mar 16 '21 06:03 Delgan

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.

Thanks for your insights! I will try giving it a rework!

afogarty85 avatar Mar 16 '21 12:03 afogarty85