Skip to content

Commit

Permalink
Create logging_example.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbharathram authored Jul 25, 2020
1 parent 4a85ad1 commit 721ce6e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions logging_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import logging

import logging

logging.debug('This is a debug message')
logging.info('This is an info message')
logging.warning('This is a warning message')
logging.error('This is an error message')
logging.critical('This is a critical message')

#

import logging

logging.basicConfig(filename='app.log', filemode='w', format='%(name)s - %(levelname)s - %(message)s')
logging.warning('This will get logged to a file')

# Create a custom logger
logger = logging.getLogger("wrapper")

# Create handlers
c_handler = logging.StreamHandler()
f_handler = logging.FileHandler('file.log')
c_handler.setLevel(logging.WARNING)
f_handler.setLevel(logging.ERROR)

# Create formatters and add it to handlers
c_format = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
f_format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
c_handler.setFormatter(c_format)
f_handler.setFormatter(f_format)

# Add handlers to the logger
logger.addHandler(c_handler)
logger.addHandler(f_handler)

logger.warning('This is a warning')
logger.error('This is an error')

0 comments on commit 721ce6e

Please sign in to comment.