Create a logger that writes to a log file and stdout.
(logging_dir)
| 164 | ################################################################################# |
| 165 | |
| 166 | def create_logger(logging_dir): |
| 167 | """ |
| 168 | Create a logger that writes to a log file and stdout. |
| 169 | """ |
| 170 | if dist.get_rank() == 0: # real logger |
| 171 | logging.basicConfig( |
| 172 | level=logging.INFO, |
| 173 | # format='[\033[34m%(asctime)s\033[0m] %(message)s', |
| 174 | format='[%(asctime)s] %(message)s', |
| 175 | datefmt='%Y-%m-%d %H:%M:%S', |
| 176 | handlers=[logging.StreamHandler(), logging.FileHandler(f"{logging_dir}/log.txt")] |
| 177 | ) |
| 178 | logger = logging.getLogger(__name__) |
| 179 | |
| 180 | else: # dummy logger (does nothing) |
| 181 | logger = logging.getLogger(__name__) |
| 182 | logger.addHandler(logging.NullHandler()) |
| 183 | return logger |
| 184 | |
| 185 | def create_accelerate_logger(logging_dir, is_main_process=False): |
| 186 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected