Add log disable and env var loglevel
This commit is contained in:
parent
eedb63212d
commit
28ee4f7197
12
CHANGELOG
12
CHANGELOG
@ -1,16 +1,20 @@
|
|||||||
|
- 0.0.17
|
||||||
|
* Add loglevel environment variable
|
||||||
|
- 0.0.16
|
||||||
|
* Allow query string in query url
|
||||||
- 0.0.14
|
- 0.0.14
|
||||||
* Add option to skip ssl verification on rpc
|
* Add option to skip ssl verification on rpc
|
||||||
- 0.0.5
|
- 0.0.5
|
||||||
* Move eth code to separate package
|
* Move eth code to separate package
|
||||||
- 0.0.4-unreleased
|
- 0.0.4
|
||||||
* Add pack tx from already signed tx struct
|
* Add pack tx from already signed tx struct
|
||||||
* Add http auth handling for jsonrpc connections
|
* Add http auth handling for jsonrpc connections
|
||||||
* Add customizable jsonrpc id generator (to allow for buggy server id handling)
|
* 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)
|
* 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 tx decode
|
||||||
* Add eth balance query with erc20 option
|
* Add eth balance query with erc20 option
|
||||||
* Add eth checksum address
|
* Add eth checksum address
|
||||||
|
@ -139,8 +139,9 @@ class ArgumentParser(argparse.ArgumentParser):
|
|||||||
:type env: dict
|
:type env: dict
|
||||||
"""
|
"""
|
||||||
if arg_flags & Flag.VERBOSE:
|
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('-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:
|
if arg_flags & Flag.CONFIG:
|
||||||
self.add_argument('-c', '--config', type=str, default=env.get('CONFINI_DIR'), help='Configuration directory')
|
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')
|
self.add_argument('-n', '--namespace', type=str, help='Configuration namespace')
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import confini
|
import confini
|
||||||
@ -102,14 +103,51 @@ class Config(confini.Config):
|
|||||||
:rtype: confini.Config
|
:rtype: confini.Config
|
||||||
:return: Processed configuation
|
: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:
|
if logger == None:
|
||||||
logger = logging.getLogger()
|
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:
|
if args.vv:
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
elif args.v:
|
elif args.v:
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
if args.no_logs:
|
||||||
|
logging.disable()
|
||||||
|
|
||||||
override_config_dirs = []
|
override_config_dirs = []
|
||||||
config_dir = [cls.default_base_config_dir]
|
config_dir = [cls.default_base_config_dir]
|
||||||
@ -160,7 +198,6 @@ class Config(confini.Config):
|
|||||||
# default_config_dir = default_parent_config_dir
|
# default_config_dir = default_parent_config_dir
|
||||||
# config_dir = default_config_dir
|
# config_dir = default_config_dir
|
||||||
# override_config_dirs = []
|
# 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 = confini.Config(config_dir, env_prefix=env_prefix, override_dirs=override_config_dirs)
|
||||||
config.process()
|
config.process()
|
||||||
|
@ -3,7 +3,7 @@ name=chainlib
|
|||||||
license=WTFPL2
|
license=WTFPL2
|
||||||
author_email=dev@holbrook.no
|
author_email=dev@holbrook.no
|
||||||
description=Generic blockchain access library and tooling
|
description=Generic blockchain access library and tooling
|
||||||
version=0.0.16
|
version=0.0.17
|
||||||
url=https://gitlab.com/chaintools/chainlib
|
url=https://gitlab.com/chaintools/chainlib
|
||||||
author=Louis Holbrook
|
author=Louis Holbrook
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user