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 948049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:10:51+00:00 2026-05-15T23:10:51+00:00

I have a package that has several components in it that would benefit greatly

  • 0

I have a package that has several components in it that would benefit greatly from using logging and outputting useful information.

What I do not want to do is to ‘setup’ proper logging for every single file with somewhere along these lines:

import logging
logging.basicConfig(level=DEBUG)
my_function = logging.getLogger("my_function")
my_class = logging.getLogger("my_class")

I have tried a couple of approaches, one of them being adding the boilerplate code into a class within a utility module and try and do something like this:

from util import setlogging
set_logging()

But even the above solution doesn’t look clean to me and would cause issues because setLogger doesn’t have a __call__ method. What I did liked was that my “set_logging” class would read form a config file and have some default values so it wouldn’t matter what level or what type of logging format I wanted it would set it up correctly.

Is there a way to initialize proper logging across the board in my package? Maybe in the __init__.py file?

And just to be as verbose as possible, this is what setlogging (now a function, not a class) looks like:

def setlogging(config=None):
    if config == None:
        config = config_options() # sets default values
    levels = {
        'debug': DEBUG,
       'info': INFO
        }

    level = levels.get(config['log_level'])
    log_format = config['log_format']
    datefmt = config['log_datefmt']

    basicConfig(
        level   = level,
        format  = log_format,
        datefmt = datefmt)
  • 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-15T23:10:52+00:00Added an answer on May 15, 2026 at 11:10 pm

    If you want all the code in the various modules of your package to use the same logger object, you just need to (make that logger available — see later — and) call

    mylogger.warning("Attenzione!")
    

    or the like, rather than logging.warning &c. So, the problem reduces to making one mylogger object for the whole package and making it available throughout the modules in the package. (Alternatively, you could used named loggers with names starting with the package’s name followed by a dot, but while that’s very much a part of the logging package functionality, I’ve personally never found it a natural way to operate).

    So, your util.setlogging function could simply be followed by, say,

    mylogger = logging.getLogger(package_name)
    

    and every module that imports util can simply use

    util.mylogger.warning('Watch out!')
    

    and the like. This seems to me to be the simplest approach, as long as the concept that all the code in the package should be logging in the same way applies.

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

Sidebar

Related Questions

I have an SSIS package that does the following: Selects the connection strings from
I have an SSIS package that executes several tasks. I manually added an event
I have a WSI installer package that I'm using to install my application. The
I have a package that I just made and I have an old-mode that
I have a DTS package that drops a table then creates it and populates
I have an SSIS package that connects to a mysql server and attempts to
I have an SSIS package that I've saved under Maintenance Plans on SQL Server
Right now I have an SSIS package that runs every morning and gives me
I have a dtsx package with a precedence constraint that evaluates an expression and
We have a number of projects that use the same and/or similar package names.

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.