Skip to content

Commit

Permalink
Update config and exceptions in python sdk for tp configs
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Gunderson <[email protected]>
  • Loading branch information
agunde406 committed Nov 15, 2017
1 parent 9aff493 commit d62db17
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
28 changes: 28 additions & 0 deletions sdk/python/sawtooth_sdk/processor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,29 @@ def _get_log_config(filename=None):
return None


def _get_processor_config(filename=None):
"""Determines if there is a proccesor config in the config directory
and returns it. If it does not exist, return None.
Arguments:
filename (str): The name of the processor config specific to the
transaction processor that is being started.
Returns:
processor_config (dict): The dictionary to set transaction processor
"""

if filename is not None:

conf_file = os.path.join(get_config_dir(), filename)
if os.path.exists(conf_file):
with open(conf_file) as fd:
raw_config = fd.read()
log_config = toml.loads(raw_config)
return log_config
return None


def get_log_dir():
"""Returns the configured data directory."""
return _get_dir(
Expand All @@ -108,3 +131,8 @@ def get_log_dir():
def get_log_config(filename=None):
"""Returns the log config dictinary if it exists."""
return _get_log_config(filename)


def get_processor_config(filename=None):
"""Returns the log config dictinary if it exists."""
return _get_processor_config(filename)
5 changes: 5 additions & 0 deletions sdk/python/sawtooth_sdk/processor/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ class InternalError(_TpResponseError):
class AuthorizationException(Exception):
"""Raised when a authorization error occurs."""
pass


class LocalConfigurationError(Exception):
"""Raised when a log configuraiton error occurs."""
pass
19 changes: 18 additions & 1 deletion sdk/python/sawtooth_sdk/processor/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@


def create_console_handler(verbose_level):
"""
Set up the console logging for a transaction processor.
Args:
verbose_level (int): The log level that the console should print out
"""
clog = logging.StreamHandler()
formatter = ColoredFormatter(
"%(log_color)s[%(asctime)s.%(msecs)03d "
Expand Down Expand Up @@ -48,13 +53,25 @@ def create_console_handler(verbose_level):
return clog


def init_console_logging(verbose_level=2, capture_std_output=False):
def init_console_logging(verbose_level=2):
"""
Set up the console logging for a transaction processor.
Args:
verbose_level (int): The log level that the console should print out
"""
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(create_console_handler(verbose_level))


def log_configuration(log_config=None, log_dir=None, name=None):
"""
Sets up the loggers for a transaction processor.
Args:
log_config (dict): A dictinary of log config options
log_dir (string): The log directory's path
name (string): The name of the expected logging file
"""
if log_config is not None:
logging.config.dictConfig(log_config)
else:
Expand Down

0 comments on commit d62db17

Please sign in to comment.