落水人员检测
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

logger.py 1.0KB

10 months ago
123456789101112131415161718192021222324252627282930
  1. # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  2. import logging
  3. import os
  4. import sys
  5. __all__ = ['setup_logger']
  6. # reference from: https://github.com/facebookresearch/maskrcnn-benchmark/blob/master/maskrcnn_benchmark/utils/logger.py
  7. def setup_logger(name, save_dir, distributed_rank, filename="log.txt", mode='w'):
  8. logger = logging.getLogger(name)
  9. logger.setLevel(logging.DEBUG)
  10. # don't log results for the non-master process
  11. if distributed_rank > 0:
  12. return logger
  13. ch = logging.StreamHandler(stream=sys.stdout)
  14. ch.setLevel(logging.DEBUG)
  15. formatter = logging.Formatter("%(asctime)s %(name)s %(levelname)s: %(message)s")
  16. ch.setFormatter(formatter)
  17. logger.addHandler(ch)
  18. if save_dir:
  19. if not os.path.exists(save_dir):
  20. os.makedirs(save_dir)
  21. fh = logging.FileHandler(os.path.join(save_dir, filename), mode=mode) # 'a+' for add, 'w' for overwrite
  22. fh.setLevel(logging.DEBUG)
  23. fh.setFormatter(formatter)
  24. logger.addHandler(fh)
  25. return logger