Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Change splunklib logging #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Conversation

zach-taylor
Copy link

I have made a couple changes to the debug logging found within the splunklib module.

Before the debug logging was going to the Python root logger, which causes recursion if I'm using the Splunk SDK to send Python debug level logs to Splunk. The splunklib module should log to its own module rather than the Python root logger. In addition I added a NullHandler to the splunklib module so its logs are, by default, not forwarded to the root logger.

If one needs to view the splunklib module's debug logs, they can do something like this:

import logging
splunklib_logger = logging.getLogger('splunklib')
splunklib_logger.addHandler(logging.FileHandler('debug.log'))

Let me know if I missed anything here, and if something needs to be changed.
Thanks!

…the root module's logger. Silence the splunklib module's logger by default.
@itay
Copy link
Contributor

itay commented Nov 14, 2014

@zach-taylor my main question is how this would interact with the logging that's done inside modular inputs and custom search commands, as they do need to have a default non-null logger.

@zach-taylor
Copy link
Author

@itay I'm actually a bit confused about those pieces..

So my code will silence any logging performed in the splunklib module (including splunklib.searchcommands and splunklib.modularinput). My code is essentially pulled from here: https://docs.python.org/2/howto/logging.html#configuring-logging-for-a-library with the assumption that libraries should be silent unless the application using the library configures it to be otherwise.

Regarding logging.py in the searchcommands module, I'm not sure what it's meant to do. It looks like it is configuring logging for the library, which according to the link above, a library should not do.

Let me know if my understanding is incorrect.

@itay
Copy link
Contributor

itay commented Nov 15, 2014

I think that's a fair question. That said, it makes sense for what those two modules end up doing. The reason that searchcommands and modularinput configure logging is to make sure that any logging the user does ends up in the right places in a Splunk installation.

As opposed to the REST API portion of the SDK, those two libraries get run in the context of Splunk itself - so they need to know where to log, what format, etc, as part of their reason to exist is to make that simpler.

Does that make sense?

@zach-taylor
Copy link
Author

That makes sense. I think a fair compromise might be to remove the NullHandler stuff. That way I can still get the logger for these modules and silence them in my application.

Would that work?

@matthewsullivan-wf
Copy link

@itay any thoughts?

My company is also running into this issue big time, and this PR would solve it.

@itay
Copy link
Contributor

itay commented Dec 9, 2014

@matthewsullivan-wf @zach-taylor that seems reasonable. I think we don't want to make it a NullHandler by default, but we should allow others to set it to a NullHandler if they want to (or whatever they want).

Does that make sense?

@zach-taylor
Copy link
Author

@itay sure thing. I can remove that default NullHandler. Would that make this work then?

@itay
Copy link
Contributor

itay commented Dec 9, 2014

As long as by default it'll log out to stdout, then yes.

@zach-taylor
Copy link
Author

@itay this should work.

@matthewsullivan-wf
Copy link

@itay quick ping :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants