Skip to content
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

Cannot disable logging #86

Closed
kbuilds opened this issue Oct 6, 2017 · 11 comments
Closed

Cannot disable logging #86

kbuilds opened this issue Oct 6, 2017 · 11 comments

Comments

@kbuilds
Copy link

kbuilds commented Oct 6, 2017

Looks like the logging info is writing to a file called anetsdk.log by default. I need to disable this log, as all messages are being handled by exceptions, and the log file is causing issues with permissions on every server that my software is being deployed to.

Any ideas on how to disable this via configuration?

@zacmiller26
Copy link

Also wondering about this

@zacmiller26
Copy link

zacmiller26 commented Nov 14, 2017

At the very least, is it possible to over-ride the variables from inside constants.py?

I'm assuming updating a variable like defaultLoggingLevel to None might disable logging?

@kbuilds
Copy link
Author

kbuilds commented Nov 15, 2017

@brianmc Are you the owner of this project at Auth.net?

@rneilson
Copy link

rneilson commented Jan 24, 2018

Honestly, I do a dirty, filthy monkey patch of the apicontrollers module:

import logging
from authorizenet import apicontractsv1, apicontrollers

log = logging.getLogger('creditcard')

if not settings.AUTHORIZE_NET_LOG:
    log.setLevel(logging.CRITICAL)

def _fake_config (*args, **kwargs): # pragma: no cover
    pass
log.basicConfig = _fake_config
apicontrollers.logging = log
apicontrollers.apicontrollersbase.logging = log

apicontrollersbase sets up a logger, and calls .basicConfig() on it to set its level and output file, so I monkey-patch that with an empty function, and set my real logging config beforehand. (The settings listed above happens to be a Django settings object, so pick your conditional to taste.)

Side note: by importing apicontrollers as a module instead of importing * from it as the docs suggest, that A) prevents logging from getting clobbered in the namespace, and B) allows only monkey-patching apicontrollers.logging, leaving you free to log what you actually want to.

@kbuilds
Copy link
Author

kbuilds commented Jan 25, 2018

@rneilson I feel like I need to shower after reading this. But if it works it works.

On a serious note, where are the maintainers for this repo?

@rneilson
Copy link

@kbuilds I almost went to confession after writing it, and I'm not even Catholic.

It mostly works -- there are still some stray error messages from pyxb, and sometimes it'll output a ContentNondeterminismError instead of stringified XML on some calls, so it's not as useful as I'd like for the times I do want to log requests and responses. But it'll definitely prevent that log file from being created.

As for maintainers: @Sapbasu15? @sunnyrajrathod?

@Sapbasu15
Copy link
Contributor

@rneilson @kbuilds we are planning to move default logging to stderr stream with critical level (almost similar to no logging), and logging level and destination (file/stream) will be configurable via ini file. Also you'll be able to add handlers to root logger and configure it if required.
Will that solve the problems you are facing regarding logging?

@rneilson
Copy link

@Sapbasu15 I would actually vastly prefer no logger configuration be done inside the library, just a standard named logger I can configure as I wish, no extra .ini file required. (If you do set any defaults on the logger, please make sure they're done at the module's top level, not when instantiating a controller like it is now.)

@Sapbasu15
Copy link
Contributor

@rneilson we can provide a named logger like 'authorizenet_sdk' and add a null handler to it, assuming a configured handler to be added by developer. Currently its using the root logger only. It seems root logger has to be configured to avoid 'no logger' messages from pyxb. Also we think it'll be good to provide some defaults for ease of use, which can be done at module level rather than base constructor.

@rneilson
Copy link

@Sapbasu15 Quite honestly, if the library configures anything on the root logger, that would be just as bad as the current setup, because it's likely to clobber (or, almost as bad, silently change) existing configuration. And I suspect if you set a null handler for the pyxb named logger as well (at the module level), that'll get rid of the No handlers could be found for logger "pyxb.binding.content" messages too.

Just don't touch my root logger, y'know?

anuragg29 added a commit that referenced this issue Jun 1, 2018
Fix for logger #86,  requests package #96 and test dependency #80
@Sapbasu15
Copy link
Contributor

Fix for the issues is released in PR #102 and has been released in the latest version.

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

No branches or pull requests

4 participants