Skip to content
Snippets Groups Projects
Commit ccc120d4 authored by roadscape's avatar roadscape
Browse files

log_level test

parent ff5ae2ce
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@ import configargparse
from hive.steem.client import SteemClient
from hive.db.adapter import Db
from hive.utils.normalize import strtobool
from hive.utils.normalize import strtobool, int_log_level
class Conf():
""" Manages sync/server configuration via args, ENVs, and hive.conf. """
......@@ -94,8 +94,4 @@ class Conf():
def log_level(self):
"""Get `logger`s internal int level from config string."""
str_log_level = self.get('log_level')
log_level = getattr(logging, str_log_level.upper(), None)
if not isinstance(log_level, int):
raise ValueError('Invalid log level: %s' % str_log_level)
return log_level
return int_log_level(self.get('log_level'))
......@@ -65,6 +65,7 @@ def run_server(conf):
log_level = conf.log_level()
config.debug = (log_level == logging.DEBUG)
#config.debug = logging.getLogger().isEnabledFor(logging.DEBUG)
logging.getLogger('jsonrpcserver.dispatcher.response').setLevel(log_level)
log = logging.getLogger(__name__)
......
"""Methods to parse steemd values and clean strings."""
import logging
import math
import decimal
from datetime import datetime
......@@ -155,3 +156,12 @@ def strtobool(val):
return False
else:
raise ValueError("not booleany: %r" % (val,))
def int_log_level(str_log_level):
"""Get `logger`s internal int level from config string."""
if not str_log_level:
raise ValueError('Empty log level passed')
log_level = getattr(logging, str_log_level.upper(), None)
if not isinstance(log_level, int):
raise ValueError('Invalid log level: %s' % str_log_level)
return log_level
......@@ -21,6 +21,7 @@ from hive.utils.normalize import (
safe_img_url,
secs_to_str,
strtobool,
int_log_level,
)
def test_secs_to_str():
......@@ -105,3 +106,15 @@ def test_strtobool():
with pytest.raises(ValueError):
strtobool('foo')
def test_int_log_level():
assert int_log_level('debug') == 10
assert int_log_level('DEBUG') == 10
assert int_log_level('info') == 20
assert int_log_level('warning') == 30
with pytest.raises(ValueError):
int_log_level('foo')
with pytest.raises(ValueError):
int_log_level(None)
with pytest.raises(ValueError):
int_log_level('')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment