22# SPDX-FileCopyrightText: Copyright (c) 2020-2025, NVIDIA CORPORATION.
33# SPDX-License-Identifier: Apache-2.0
44#
5-
6- # distutils: language = c++
7-
8-
9- import logging
105import sys
116
127
@@ -23,6 +18,7 @@ cdef void _log_callback(int lvl, const char * msg) with gil:
2318 """
2419 print (msg.decode(' utf-8' ), end= ' ' )
2520
21+
2622cdef void _log_flush() with gil:
2723 """
2824 Default spdlogs callback function to flush logs
@@ -38,12 +34,7 @@ def _verbose_to_level(verbose: bool | int) -> level_enum:
3834 elif verbose is False:
3935 return level_enum.info
4036 else:
41- return level_enum(6 - verbose )
42-
43-
44- def _verbose_from_level(level: level_enum ) -> int:
45- """Convert a `level_enum` back into an equivalent `verbose` parameter value."""
46- return 6 - int(level )
37+ return level_enum(max(6 - verbose , 0))
4738
4839
4940cdef class LogLevelSetter:
@@ -179,7 +170,7 @@ def should_log_for(level):
179170 return default_logger().should_log(level)
180171
181172
182- def _log (level_enum lvl , msg , default_func ):
173+ def _log (level_enum lvl , msg ):
183174 """
184175 Internal function to log a message at a given level.
185176
@@ -189,8 +180,6 @@ def _log(level_enum lvl, msg, default_func):
189180 Logging level to be set.
190181 msg : str
191182 Message to be logged.
192- default_func : function
193- Default logging function to be used if GPU build is disabled.
194183 """
195184 cdef string s = msg.encode(" UTF-8" )
196185 default_logger().log(lvl, s)
@@ -200,115 +189,73 @@ def trace(msg):
200189 """
201190 Logs a trace message, if it is enabled.
202191
203- Examples
204- --------
205-
206- .. code-block:: python
207-
208- logger.trace("Hello world! This is a trace message")
209-
210192 Parameters
211193 ----------
212194 msg : str
213195 Message to be logged.
214196 """
215197 # No trace level in Python so we use the closest thing, debug.
216- _log(level_enum.trace, msg, logging.debug )
198+ _log(level_enum.trace, msg)
217199
218200
219201def debug (msg ):
220202 """
221203 Logs a debug message, if it is enabled.
222204
223- Examples
224- --------
225-
226- .. code-block:: python
227-
228- logger.debug("Hello world! This is a debug message")
229-
230205 Parameters
231206 ----------
232207 msg : str
233208 Message to be logged.
234209 """
235- _log(level_enum.debug, msg, logging.debug )
210+ _log(level_enum.debug, msg)
236211
237212
238213def info (msg ):
239214 """
240215 Logs an info message, if it is enabled.
241216
242- Examples
243- --------
244-
245- .. code-block:: python
246-
247- logger.info("Hello world! This is a info message")
248-
249217 Parameters
250218 ----------
251219 msg : str
252220 Message to be logged.
253221 """
254- _log(level_enum.info, msg, logging.info )
222+ _log(level_enum.info, msg)
255223
256224
257225def warn (msg ):
258226 """
259227 Logs a warning message, if it is enabled.
260228
261- Examples
262- --------
263-
264- .. code-block:: python
265-
266- logger.warn("Hello world! This is a warning message")
267-
268229 Parameters
269230 ----------
270231 msg : str
271232 Message to be logged.
272233 """
273- _log(level_enum.warn, msg, logging.warn )
234+ _log(level_enum.warn, msg)
274235
275236
276237def error (msg ):
277238 """
278239 Logs an error message, if it is enabled.
279240
280- Examples
281- --------
282-
283- .. code-block:: python
284-
285- logger.error("Hello world! This is a error message")
286-
287241 Parameters
288242 ----------
289243 msg : str
290244 Message to be logged.
291245 """
292- _log(level_enum.error, msg, logging.error )
246+ _log(level_enum.error, msg)
293247
294248
295249def critical (msg ):
296250 """
297251 Logs a critical message, if it is enabled.
298252
299- Examples
300- --------
301-
302- .. code-block:: python
303-
304- logger.critical("Hello world! This is a critical message")
305-
306253 Parameters
307254 ----------
308255 msg : str
309256 Message to be logged.
310257 """
311- _log(level_enum.critical, msg, logging.critical )
258+ _log(level_enum.critical, msg)
312259
313260
314261def flush ():
0 commit comments