1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright 2018-2021 The glTF-Blender-IO authors.
15 OUTPUT_LEVELS
= ['ERROR', 'WARNING', 'INFO', 'PROFILE', 'DEBUG', 'VERBOSE']
17 g_current_output_level
= 'DEBUG'
18 g_profile_started
= False
28 def set_output_level(level
):
29 """Set an output debug level."""
30 global g_current_output_level
32 if OUTPUT_LEVELS
.index(level
) < 0:
35 g_current_output_level
= level
38 def print_console(level
, output
):
39 """Print to Blender console with a given header and output."""
41 global g_current_output_level
43 if OUTPUT_LEVELS
.index(level
) > OUTPUT_LEVELS
.index(g_current_output_level
):
46 print(get_timestamp() + " | " + level
+ ': ' + output
)
50 """Print a new line to Blender console."""
55 current_time
= time
.gmtime()
56 return time
.strftime("%H:%M:%S", current_time
)
59 def print_timestamp(label
=None):
60 """Print a timestamp to Blender console."""
61 output
= 'Timestamp: ' + get_timestamp()
64 output
= output
+ ' (' + label
+ ')'
66 print_console('PROFILE', output
)
70 """Start profiling by storing the current time."""
71 global g_profile_start
72 global g_profile_started
75 print_console('ERROR', 'Profiling already started')
78 g_profile_started
= True
80 g_profile_start
= time
.time()
83 def profile_end(label
=None):
84 """Stop profiling and printing out the delta time since profile start."""
86 global g_profile_delta
87 global g_profile_started
89 if not g_profile_started
:
90 print_console('ERROR', 'Profiling not started')
93 g_profile_started
= False
95 g_profile_end
= time
.time()
96 g_profile_delta
= g_profile_end
- g_profile_start
98 output
= 'Delta time: ' + str(g_profile_delta
)
100 if label
is not None:
101 output
= output
+ ' (' + label
+ ')'
103 print_console('PROFILE', output
)
106 # TODO: need to have a unique system for logging importer/exporter
107 # TODO: this logger is used for importer, but in io and in blender part, but is written here in a _io_ file
109 def __init__(self
, loglevel
):
110 self
.logger
= logging
.getLogger('glTFImporter')
111 self
.hdlr
= logging
.StreamHandler()
112 formatter
= logging
.Formatter('%(asctime)s %(levelname)s %(message)s')
113 self
.hdlr
.setFormatter(formatter
)
114 self
.logger
.addHandler(self
.hdlr
)
115 self
.logger
.setLevel(int(loglevel
))