forked from NVIDIAGameWorks/kaolin-wisp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_utils.py
39 lines (31 loc) · 1.35 KB
/
app_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# NVIDIA CORPORATION & AFFILIATES and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION & AFFILIATES is strictly prohibited.
import logging
import sys
import pprint
def default_log_setup(level=logging.INFO):
"""
Sets up default logging, always logging to stdout.
:param level: logging level, e.g. logging.INFO
"""
handlers = [logging.StreamHandler(sys.stdout)]
# TODO: better to also use loggers per file and add %(name)15s
logging.basicConfig(level=level,
format='%(asctime)s|%(levelname)8s| %(message)s',
handlers=handlers)
def args_to_log_format(args_dict) -> str:
"""Convert args hierarchy to string representation suitable for logging (i.e. with Tensorboard).
Args:
args_dict : The parsed arguments, grouped within a dictionary.
Returns:
arg_str : The args encoded in a string format.
"""
pp = pprint.PrettyPrinter(indent=2)
args_str = pp.pformat(args_dict)
args_str = f'```{args_str}```'
return args_str