get_logger#
- scikitplot.sp_logging.get_logger()[source]#
Return SP (scikitplot) logger instance.
- Returns:
- logging.Logger
An instance of the Python logging library Logger.
- Return type:
See also
SpLogger
A singleton logger class that provides a shared
logging.Logger
instance with customizable name, formatter, handler, logging level, and thread-safety.sp_logger
An instance of
SpLogger
class, providing logging functionality.logging.getLogger
Standard library function to retrieve
logging.Logger
instance. For more: https://docs.python.org/3/library/logging.html_is_jupyter_notebook
Determines if the environment is a Jupyter notebook. For define
use_stderr
.
Notes
See Python documentation (https://docs.python.org/3/library/logging.html) for detailed API. Below is only a summary.
The logger has 5 levels of logging from the most serious to the least:
FATAL
ERROR
WARNING
INFO
DEBUG
The logger has the following methods, based on these logging levels:
fatal(msg, *args, **kwargs)
error(msg, *args, **kwargs)
warn(msg, *args, **kwargs)
info(msg, *args, **kwargs)
debug(msg, *args, **kwargs)
The
msg
can contain string formatting. An example of logging at theERROR
level using string formatting is:>>> sp.get_logger().error("The value %d is invalid.", 3)
You can also specify the logging verbosity. In this case, the WARN level log will not be emitted:
>>> sp.get_logger().setLevel(sp.sp_logging.WARNING) >>> sp.get_logger().debug( ... "This is a debug." ... ) # This will not be shown, as level is WARNING. >>> sp.get_logger().info( ... "This is a info." ... ) # This will not be shown, as level is WARNING. >>> sp.get_logger().warning("This is a warning.")
Examples
Get a root logger by module:
>>> import scikitplot.sp_logging as logging # module logger >>> logging.setLevel(logging.INFO) # default WARNING >>> logging.info("This is a info message from the sp logger.")
2025-02-14 16:18:52 INFO scikitplot 139702396426048 sp_logging.py 882 This is a info message from the sp logger.
Get a root logger by func:
>>> from scikitplot import sp_logging, get_logger ... ... logging = get_logger() # pure python logger, not have direct log level >>> logging.setLevel(sp_logging.INFO) # default WARNING >>> logging.info("This is a info message from the sp logger.")
2025-02-14 16:18:53 INFO scikitplot 139702396426048 867886142.py 5 This is a info message from the sp logger.
Get a root logger by class:
>>> from scikitplot import SpLogger ... ... logging = SpLogger() # class logger >>> logging.setLevel(logging.INFO) # default WARNING >>> logging.info("This is a info message from the sp logger.")
2025-02-14 16:18:53 INFO scikitplot 139702396426048 sp_logging.py 1232 This is a info message from the sp logger.
Get a root logger by class instance:
>>> from scikitplot import ( ... sp_logger as logging, ... ) # class instance logger >>> logging.setLevel(logging.INFO) # default WARNING >>> logging.info("This is a info message from the sp logger.")
2025-02-14 16:18:53 INFO scikitplot 139702396426048 sp_logging.py 1232 This is a info message from the sp logger.