MCPcopy
hub / github.com/cs230-stanford/cs230-code-examples / set_logger

Function set_logger

tensorflow/vision/model/utils.py:38–64  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

36
37
38def 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
67def save_dict_to_json(d, json_path):

Callers 2

train.pyFile · 0.90
evaluate.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected