Sets the logger to log info in terminal and file `log_path`. In general, it is useful to have a logger so that every output to the terminal is saved in a permanent file. Here we save it to `model_dir/train.log`. Example: ``` logging.info("Starting training...") ``` Arg
(log_path)
| 36 | |
| 37 | |
| 38 | def set_logger(log_path): |
| 39 | """Sets the logger to log info in terminal and file `log_path`. |
| 40 | |
| 41 | In general, it is useful to have a logger so that every output to the terminal is saved |
| 42 | in a permanent file. Here we save it to `model_dir/train.log`. |
| 43 | |
| 44 | Example: |
| 45 | ``` |
| 46 | logging.info("Starting training...") |
| 47 | ``` |
| 48 | |
| 49 | Args: |
| 50 | log_path: (string) where to log |
| 51 | """ |
| 52 | logger = logging.getLogger() |
| 53 | logger.setLevel(logging.INFO) |
| 54 | |
| 55 | if not logger.handlers: |
| 56 | # Logging to a file |
| 57 | file_handler = logging.FileHandler(log_path) |
| 58 | file_handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s: %(message)s')) |
| 59 | logger.addHandler(file_handler) |
| 60 | |
| 61 | # Logging to console |
| 62 | stream_handler = logging.StreamHandler() |
| 63 | stream_handler.setFormatter(logging.Formatter('%(message)s')) |
| 64 | logger.addHandler(stream_handler) |
| 65 | |
| 66 | |
| 67 | def save_dict_to_json(d, json_path): |
no outgoing calls
no test coverage detected