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

  • Home
  • SEARCH
  • 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 3789444
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:09:28+00:00 2026-05-19T12:09:28+00:00

I have a single logger with multiple handlers, which have their own formatters. Now

  • 0

I have a single logger with multiple handlers, which have their own formatters. Now I want to add an indenting feature, with the indent level controlled at runtime. I want messages from all the handlers to get this indent. I’ve tried to create it as a filter, but found that I seem to be unable to alter the message content. Then I’ve tried it as a formatter, but I can only have one per handler. How can I add such indentation without explicitly changing the formatters of every handler?
I should mention that one of the formatters I have is a class that adds color to the output. It is not a simple format string.


In addition, I am using a config file. Ideally, I’d like to be able to drive this mostly from there. However, I need to modify the state of the indent formatter (e.g. set indent level), but I don’t know how to get to that particular formatter as there’s no logger.getFormatter("by_name") method.
To clarify, I need to access the specific formatter instance, essentially to adjust the format on the fly. The instance has been created by logging.config from the file. I don’t find any accessor methods that would allow me to get the particular formatter given its name.

  • 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-05-19T12:09:29+00:00Added an answer on May 19, 2026 at 12:09 pm

    Here’s another, hacky, but simple one. My messages for all handlers always start with a message level string. Just modify those darn strings on every indent change:

    # (make a LEVELS dict out of all the logging levels first)    
    def indent(self, step = 1):
            "Change the current indent level by the step (use negative to decrease)"
            self._indent_level += step
            if self._indent_level < 0:
                self._indent_level = 0
            self._indent_str = self._indent_str_base * self._indent_level
            for lvl in LEVELS:
                level_name = self._indent_str + LEVELS[lvl]
                logging.addLevelName(lvl, level_name)
    

    (see my other answer for the stuff that surrounds indent function)
    Now the indenter can be an independent class without messing with the details of logging process. As long as the message includes the level string, the indent will be there, even if some stuff is coming before it. Not ideal in general, but may work for me.
    Anybody has more ideas that work for any msg format?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large list of phrases (single and multiple words; some overlapping) and
I'm using Log4Net 2.0, I have it working as required but which to add
I have a medium-complex Rails app. The main controller (the one that does what
I have a job in Hadoop 0.20 that needs to operate on large files,
I have a relatively simple entries model with just five fields: id type (what
I am looking to create an admin side for my website, which is built
I have been trying for last 3 days still i am not able to
Simply put, I am trying to create a custom logger for visitors to a
I'm attempting to retrieve the value of a single element in an XML file.
The WindsorContainer::Resolve method doesn't seem to be paying close enough attention to the arguments

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.