Skip to content

Commit

Permalink
Create logger function to instantiate a logger and return it.
Browse files Browse the repository at this point in the history
  • Loading branch information
hreikin committed Apr 9, 2022
1 parent 69ddbdf commit afd3d1c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tkintermd/log.py
@@ -0,0 +1,42 @@
import logging

##################################### LOGS #####################################
# Initialize the logger and specify the level of logging. This will log "DEBUG"
# and higher messages to file and log "WARNING" and higher messages to the console.

def create_logger():
logging.basicConfig(level=logging.DEBUG,
format='[%(levelname)s][%(name)s][%(asctime)s]: %(message)s',
datefmt='%d-%m-%y-%H:%M:%S',
filename='debug.log',
filemode='a')

# Define a "handler" which writes "WARNING" messages or higher to the "sys.stderr".
console = logging.StreamHandler()
console.setLevel(logging.WARNING)

# Set a format which is simpler for console messages.
formatter = logging.Formatter('[%(levelname)s][%(asctime)s]: %(message)s', datefmt='%H:%M:%S')

# Tell the console "handler" to use this format.
console.setFormatter(formatter)

# Add the "handler" to the "root logger".
log = logging.getLogger(__name__)
log.addHandler(console)

return log

# Example Usage
#
# import tkintermd.log as logg
#
# logger = log.create_logger()
# logger.debug("DEBUG")
# logger.info("INFO")
# logger.exception("EXCEPTION")
# logger.warning("WARNING")
# logger.error("ERROR")
# logger.critical("CRITICAL")

################################################################################

0 comments on commit afd3d1c

Please sign in to comment.