Updated sample logger config.
This commit is contained in:
parent
bbd0256291
commit
6f28f39639
|
|
@ -66,16 +66,18 @@ __docs__ = [
|
||||||
logger = logging.getLogger(name=__name__)
|
logger = logging.getLogger(name=__name__)
|
||||||
|
|
||||||
|
|
||||||
def setup_logging(logging_obj, verbose=False):
|
def setup_logging(logging_obj, log_file, verbose=False):
|
||||||
"""Function to setup logging configuration and test it.
|
"""Function to setup logging configuration and test it.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
logging_obj: A logging instance, returned from logging.getLogger().
|
logging_obj: A logging instance, returned from logging.getLogger().
|
||||||
|
log_file: File path to write log messages to.
|
||||||
verbose: Whether or not to enable the debug level in STDERR output.
|
verbose: Whether or not to enable the debug level in STDERR output.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
>>> sample_logger = logging.getLogger(name=__name__)
|
>>> sample_logger = logging.getLogger(name=__name__)
|
||||||
>>> sample_logger = setup_logging(sample_logger)
|
>>> log_path = "sample.log"
|
||||||
|
>>> setup_logging(sample_logger, log_path, verbose=True)
|
||||||
>>> sample_logger.debug("This is a debug message")
|
>>> sample_logger.debug("This is a debug message")
|
||||||
>>> sample_logger.info("This is an info message")
|
>>> sample_logger.info("This is an info message")
|
||||||
>>> sample_logger.warning("This is a warning message")
|
>>> sample_logger.warning("This is a warning message")
|
||||||
|
|
@ -100,7 +102,7 @@ def setup_logging(logging_obj, verbose=False):
|
||||||
stderr_handle.setFormatter(log_format)
|
stderr_handle.setFormatter(log_format)
|
||||||
|
|
||||||
# Setup file logging
|
# Setup file logging
|
||||||
file_handle = logging.FileHandler("sample.log", "a")
|
file_handle = logging.FileHandler(log_file, "a")
|
||||||
file_handle.setLevel(logging.DEBUG)
|
file_handle.setLevel(logging.DEBUG)
|
||||||
file_handle.setFormatter(log_format)
|
file_handle.setFormatter(log_format)
|
||||||
|
|
||||||
|
|
@ -108,9 +110,7 @@ def setup_logging(logging_obj, verbose=False):
|
||||||
logging_obj.addHandler(stderr_handle)
|
logging_obj.addHandler(stderr_handle)
|
||||||
logging_obj.addHandler(file_handle)
|
logging_obj.addHandler(file_handle)
|
||||||
|
|
||||||
return logging_obj
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
setup_logging(logger)
|
setup_logging(logger, "sample.log")
|
||||||
logger.warning("This is a warning!")
|
logger.warning("This is a warning!")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
__author__ = "Chapin Bryce"
|
__author__ = "Chapin Bryce"
|
||||||
__authors__ = ["Chapin Bryce", "Brittney Argirakis"]
|
__authors__ = ["Chapin Bryce", "Brittney Argirakis"]
|
||||||
__license__ = ""
|
__license__ = "MIT"
|
||||||
__version__ = "0.1.1"
|
__version__ = "0.1.2"
|
||||||
__copyright__ = "2020, Chapin Bryce"
|
__copyright__ = "2020, Chapin Bryce"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue