Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:12:49+00:00 2026-06-12T00:12:49+00:00

I am using python’s standard logging system to log my application. I want to

  • 0

I am using python’s standard logging system to log my application. I want to print all types of messages (debug through critical) to the console, but I also want to send an email if the message level is error or higher. I’ve been reading about the logging documentation, but it was a bit confusing. I set up the following test, but it doesn’t seem to work correctly:

 import logging

 log = logging.getLogger('my_test_log')
 sublog = logging.getLogger('my_test_log.sublog')

 log.setLevel(logging.ERROR)
 log.addHandler(logging.StreamHandler())

 sublog.addHandler(logging.StreamHandler())
 sublog.setLevel(logging.DEBUG)     

 sublog.debug('This is a debug message')
 sublog.info('This is an info message')
 sublog.warn('This is a warn message')
 sublog.error('This is an error message')
 sublog.critical('This is a critical message')

NOTE: I set up both logs to StreamHandler right now because I don’t want to spam email yet, but it should technically just print the error and critical message twice instead of sending it to email in this situation. I will change this to SMTP after this works to email it off

This is my output when I run this code:

This is a debug message
This is a debug message
This is an info message
This is an info message
This is a warn message
This is a warn message
This is an error message
This is an error message
This is a critical message
This is a critical message

Basically everything gets printed twice rather than just the error and critical messages. What am I doing wrong here? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:12:50+00:00Added an answer on June 12, 2026 at 12:12 am

    After some quick research, it seems that Handler objects don’t automatically use their parent Logger’s log level. You’ll have to set the level yourself.

    import logging
    
    log = logging.getLogger('my_test_log')
    sublog = logging.getLogger('my_test_log.sublog')
    
    log.setLevel(logging.ERROR)
    handler = logging.StreamHandler()
    handler.setLevel(logging.ERROR)
    log.addHandler(handler)
    
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Python I want to replace all URLs in a body of text with
Using Python, I want to know whether Java is installed.
Using Python I want to randomly rearrange sections of a string based on a
Using Python I need to delete all characters in a multiline string up to
Using Python 2.6 I want to be able to convert numbers such as 00000,
Using Python I want to create a symbolic link pointing to a path that
Using Python... How can I select all of the Sundays (or any day for
Using Python regular expressions how can you get a True / False returned? All
I'm using Python Flask to run Python for web through FCGI with nginx. My
Using Python, how do I print the lines of a text file, given a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.