Skip to content

Commit

Permalink
always set logging
Browse files Browse the repository at this point in the history
  • Loading branch information
gr0vity-dev committed Apr 24, 2023
1 parent 62c989a commit 3aa9d63
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions nanolocal/nl_module.py
Expand Up @@ -7,6 +7,7 @@
from subprocess import call, run, check_output, CalledProcessError, STDOUT, PIPE
import copy
import time
import sys

from nanolocal.common.nl_parse_config import ConfigParser
from nanolocal.common.nl_parse_config import ConfigReadWrite
Expand All @@ -27,9 +28,6 @@
# * reset (remove all blocks except genesis blocks by deleting data.ldb)
# * destroy (destroy all autogenerated resources, so that we can start from virgin state next time)

logging.basicConfig(level=logging.INFO,
format='[%(asctime)s] [%(levelname)s] - %(message)s')

_conf_rw = ConfigReadWrite()
_nano_lib = NanoLibTools()
_conf = ConfigParser()
Expand Down Expand Up @@ -502,22 +500,24 @@ def run_test(self):
shell=True)

def set_log_level(self, loglevel):
if loglevel == "DEBUG":
logging.basicConfig(level=logging.DEBUG)
elif loglevel == "INFO":
logging.basicConfig(level=logging.INFO)
elif loglevel == "WARNING":
logging.basicConfig(level=logging.WARNING)
elif loglevel == "ERROR":
logging.basicConfig(level=logging.ERROR)
logging.basicConfig(
level=logging.INFO,
format='[%(asctime)s] [%(levelname)s] - %(message)s',
stream=sys.stdout)

level = logging.getLevelName(loglevel.upper())
if not isinstance(level, int):
raise ValueError(f'Invalid log level: {loglevel}')

logger = logging.getLogger()
logger.setLevel(level)

# set success level
logging.SUCCESS = 25 # between WARNING and INFO
logging.addLevelName(logging.SUCCESS, 'SUCCESS')
setattr(
logging.getLogger(), 'success',
lambda message, *args: logging.getLogger()._log(
logging.SUCCESS, message, args))
logger, 'success',
lambda message, *args: logger._log(logging.SUCCESS, message, args))

def run_command(self,
command,
Expand Down

0 comments on commit 3aa9d63

Please sign in to comment.