0

There is a Python package for SignalFx: link to GitHub source

In one of its files, it makes a _logger object that uses Python's logging library. The package has many _logger.debug() statements that make it useful in debugging connectivity problems.

The code instantiates the _logger as a global variable, like so:

_logger = logging.getLogger(__name__)

Source line in GitHub

I have searched for a while, and can't figure out how to view the _logger.debug()'s output. How can I get the _logger to print to stdout? Or, where can I view the log statements?

Thank you in advance!

Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119

2 Answers2

1

You probably need to configure logging in your application which uses SignalFx. For example, this might work in your main program script:

if __name__ == '__main__':
    import logging  # if not done already

    logging.basicConfig(level=logging.DEBUG, format='%(name)s %(message)s')

    # and then the rest of your script's code

If that doesn't produce results, you probably need to give more information about how your code that uses SignalFx is organised.

Vinay Sajip
  • 95,872
  • 14
  • 179
  • 191
0

Okay to circle back on this one, I finally have an answer built up based on two questions:

  1. The question here: How to use logging.getLogger(__name__) in multiple modules
  2. The answer here: https://stackoverflow.com/a/56840272/11163122

The first question was useful because I realized why the package used getLogger(__name__). It also made me realize I just needed to get access to the package's base logger, named signalfx.

The second answer was useful because I realized I could basically import the logger without needing to import _logger from SignalFx.

My final solution (in my code), was this:

sfx_logger = logging.getLogger("signalfx")
sfx_logger.setLevel(logging.DEBUG)
sfx_logger.addHandler(logging.StreamHandler(sys.stdout))

Now, the SignalFx logger prints to stdout, and I can see all the debug statements!

Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119