Logger’s In Python

1. Simple Example To Show The Use Loggers(Console Appender) In python3.

 import logging

logging.debug("Dubugging")
logging.info("Information")
logging.warning("Warning")
logging.error("Errors")
logging.critical("High Priority Message")

2. Simple Example To Show The Use Loggers(File Appender) In python3.

import logging


logging.basicConfig(filename='kkar_logs.log', filemode='w',
format='%(levelname)s -> %(asctime)s: %(message)s',
                    level=logging.DEBUG)

logging.warning("Warning")
logging.info("Information")
logging.debug("Debugging")

3. Simple Example To Show The Use Custom Loggers(File Appender) In python3.

import logging


logging.basicConfig(filename='kkar_logs.log', filemode='w',
                    format='%(levelname)s -> %(asctime)s:'
                           ' %(message)s', level=logging.DEBUG)
logger = logging.getLogger(__name__)

logger.info("custom logging.")
shubham = {'name': 'Shubham', 'roll': 1}
logger.debug("Shubham: %s", shubham)

4. Simple Example To Show The Use Simple Loggers(File Appender) In python3.

import logging


logging.basicConfig(filename='kkar_logs.log', filemode='w',
                    format='%(levelname)s: %(message)s',
                    level=logging.DEBUG)

logging.warning("Warning")
logging.info("Information")
logging.debug("Debugging.")