Updated sample logger config.

This commit is contained in:
Chapin Bryce 2020-10-21 18:38:12 -04:00
parent bbd0256291
commit 6f28f39639
No known key found for this signature in database
GPG Key ID: AF835C2DD0747B6C
2 changed files with 8 additions and 8 deletions

View File

@ -66,16 +66,18 @@ __docs__ = [
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.
Args:
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.
Examples:
>>> 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.info("This is an info 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)
# Setup file logging
file_handle = logging.FileHandler("sample.log", "a")
file_handle = logging.FileHandler(log_file, "a")
file_handle.setLevel(logging.DEBUG)
file_handle.setFormatter(log_format)
@ -108,9 +110,7 @@ def setup_logging(logging_obj, verbose=False):
logging_obj.addHandler(stderr_handle)
logging_obj.addHandler(file_handle)
return logging_obj
if __name__ == "__main__":
setup_logging(logger)
setup_logging(logger, "sample.log")
logger.warning("This is a warning!")

View File

@ -1,5 +1,5 @@
__author__ = "Chapin Bryce"
__authors__ = ["Chapin Bryce", "Brittney Argirakis"]
__license__ = ""
__version__ = "0.1.1"
__license__ = "MIT"
__version__ = "0.1.2"
__copyright__ = "2020, Chapin Bryce"