Skip to content

Commit 23abe85

Browse files
author
Alexander Roth
committed
Added logging
1 parent b995236 commit 23abe85

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

oauthclient/credentialutil.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,21 @@
1515
See the License for the specific language governing permissions and
1616
limitations under the License.
1717
"""
18-
import yaml, json
19-
import logging
18+
import yaml, json, os, sys
2019
from .model.model import environment, credentials
2120

21+
22+
import logging
23+
logger = logging.getLogger(str(os.getpid()) +'."'+__file__+'"')
24+
# check if there are parents handlers. If not then add console output
25+
if len(logging.getLogger(str(os.getpid())).handlers) == 0:
26+
logger.setLevel(logging.DEBUG)
27+
fh = logging.StreamHandler(sys.stdout)
28+
fh.setLevel(logging.DEBUG)
29+
logger.addHandler(fh)
30+
logger.debug('Loaded '+ __file__)
31+
32+
2233
user_config_ids = ["sandbox-user", "production-user"]
2334

2435
class credentialutil(object):
@@ -30,7 +41,7 @@ class credentialutil(object):
3041

3142
@classmethod
3243
def load(cls, app_config_path):
33-
logging.info("Loading credential configuration file at: %s", app_config_path)
44+
logger.info("Loading credential configuration file at: %s", app_config_path)
3445
with open(app_config_path, 'r') as f:
3546
if app_config_path.endswith('.yaml') or app_config_path.endswith('.yml'):
3647
content = yaml.load(f)
@@ -43,7 +54,7 @@ def load(cls, app_config_path):
4354
@classmethod
4455
def _iterate(cls, content):
4556
for key in content:
46-
logging.debug("Environment attempted: %s", key)
57+
logger.debug("Environment attempted: %s", key)
4758

4859
if key in [environment.PRODUCTION.config_id, environment.SANDBOX.config_id]:
4960
client_id = content[key]['appid']
@@ -63,7 +74,7 @@ def get_credentials(cls, env_type):
6374
"""
6475
if len(cls._credential_list) == 0:
6576
msg = "No environment loaded from configuration file"
66-
logging.error(msg)
77+
logger.error(msg)
6778
raise CredentialNotLoadedError(msg)
6879
return cls._credential_list[env_type.config_id]
6980

oauthclient/oauth2api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def get_access_token(self, env_type, refresh_token, scopes):
120120
refresh token call
121121
"""
122122

123-
logger.info("Trying to get a new user access token ... ")
123+
logger.debug("Trying to get a new user access token ... ")
124124

125125
credential = credentialutil.get_credentials(env_type)
126126

0 commit comments

Comments
 (0)