Add log disable and env var loglevel

This commit is contained in:
lash 2022-01-21 00:13:07 +00:00
parent eedb63212d
commit 28ee4f7197
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 50 additions and 8 deletions

View File

@ -1,16 +1,20 @@
- 0.0.17
* Add loglevel environment variable
- 0.0.16
* Allow query string in query url
- 0.0.14
* Add option to skip ssl verification on rpc
- 0.0.5
* Move eth code to separate package
- 0.0.4-unreleased
- 0.0.4
* Add pack tx from already signed tx struct
* Add http auth handling for jsonrpc connections
* Add customizable jsonrpc id generator (to allow for buggy server id handling)
- 0.0.3-unreleased
- 0.0.3
* Remove erc20 module (to new external package)
- 0.0.2-unreleased
- 0.0.2
*
- 0.0.1-unreleased
- 0.0.1
* Add eth tx decode
* Add eth balance query with erc20 option
* Add eth checksum address

View File

@ -139,8 +139,9 @@ class ArgumentParser(argparse.ArgumentParser):
:type env: dict
"""
if arg_flags & Flag.VERBOSE:
self.add_argument('--no-logs', dest='no_logs',action='store_true', help='Turn off all logging')
self.add_argument('-v', action='store_true', help='Be verbose')
self.add_argument('-vv', action='store_true', help='Be more verbose')
self.add_argument('-vv', action='store_true', help='Be very verbose')
if arg_flags & Flag.CONFIG:
self.add_argument('-c', '--config', type=str, default=env.get('CONFINI_DIR'), help='Configuration directory')
self.add_argument('-n', '--namespace', type=str, help='Configuration namespace')

View File

@ -2,6 +2,7 @@
import logging
import os
import sys
import re
# external imports
import confini
@ -102,14 +103,51 @@ class Config(confini.Config):
:rtype: confini.Config
:return: Processed configuation
"""
env_prefix = getattr(args, 'env_prefix', None)
env_prefix_str = env_prefix
if env_prefix_str == None:
env_prefix_str = ''
else:
env_prefix_str += '_'
env_loglevel_key_str = env_prefix_str + 'LOGLEVEL'
env_loglevel = os.environ.get(env_loglevel_key_str)
if logger == None:
logger = logging.getLogger()
if arg_flags & Flag.CONFIG:
if env_loglevel != None:
env_loglevel = env_loglevel.lower()
if env_loglevel == '0' or env_loglevel == 'no' or env_loglevel == 'none' or env_loglevel == 'disable' or env_loglevel == 'disabled' or env_loglevel == 'off':
logging.disable()
elif env_loglevel == '1' or env_loglevel == 'err' or env_loglevel == 'error':
logger.setLevel(logging.ERROR)
elif env_loglevel == '2' or env_loglevel == 'warning' or env_loglevel == 'warn':
logger.setLevel(logging.WARNING)
elif env_loglevel == '3' or env_loglevel == 'info':
logger.setLevel(logging.INFO)
else:
valid_level = False
try:
num_loglevel = int(env_loglevel)
valid_level = True
except:
if env_loglevel == 'debug':
valid_level = True
if not valid_level:
raise ValueError('unknown loglevel {} set in environment variable {}'.format(env_loglevel, env_loglevel_key_str))
logger.setLevel(logging.DEBUG)
if arg_flags & Flag.VERBOSE:
if args.vv:
logger.setLevel(logging.DEBUG)
elif args.v:
logger.setLevel(logging.INFO)
if args.no_logs:
logging.disable()
override_config_dirs = []
config_dir = [cls.default_base_config_dir]
@ -160,7 +198,6 @@ class Config(confini.Config):
# default_config_dir = default_parent_config_dir
# config_dir = default_config_dir
# override_config_dirs = []
env_prefix = getattr(args, 'env_prefix', None)
config = confini.Config(config_dir, env_prefix=env_prefix, override_dirs=override_config_dirs)
config.process()

View File

@ -3,7 +3,7 @@ name=chainlib
license=WTFPL2
author_email=dev@holbrook.no
description=Generic blockchain access library and tooling
version=0.0.16
version=0.0.17
url=https://gitlab.com/chaintools/chainlib
author=Louis Holbrook