title: Python: How to create and use a custom logger in python use logging module?
body: <p>I am trying to create a custom logger as in the code below. However, no matter what level I pass to the function, logger only prints warning messages. For example even if I set the argument <strong>level = logging.DEBUG</strong> by default my code fails to log the debug or info messages. Can someone point out the problem here. </p>
  
  <pre><code>import boto3
  import logging
  
  
  def get_logger(name=__name__, level=logging.DEBUG):
      # Create log handler
      logHandler = logging.StreamHandler()
      logHandler.setLevel(level)
  
      # Set handler format
      logFormat = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s", datefmt="%d-%b-%y")
      logHandler.setFormatter(logFormat)
  
      # Create logger
      logger = logging.getLogger(name)
      # Add handler to logger
      logger.addHandler(logHandler)
  
      # Stop propagating the log messages to root logger
      # logger.propagate = False
  
      return logger
  
  
  def listBuckets():
  
      logThis = get_logger(level=logging.DEBUG)
  
      s3 = boto3.resource('s3')
      for bucket in s3.buckets.all():
          logThis.debug(msg='This message is from logger')
          print(bucket.name)
  
  
  listBuckets()
  </code></pre>