forked from p15670423/monkey
Move `DEFAULT_LOG_LEVEL` and add function `load_server_config` to monkey_island.py
This commit is contained in:
parent
3c7687a405
commit
e8c1c81edf
|
@ -7,16 +7,13 @@ gevent_monkey.patch_all()
|
||||||
import json # noqa: E402
|
import json # noqa: E402
|
||||||
import os # noqa: E402
|
import os # noqa: E402
|
||||||
|
|
||||||
from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR, DEFAULT_LOG_LEVEL # noqa: E402
|
from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR # noqa: E402
|
||||||
from monkey_island.cc.server_utils.island_logger import setup_logging # noqa: E402
|
from monkey_island.cc.server_utils.island_logger import setup_logging # noqa: E402
|
||||||
|
|
||||||
if "__main__" == __name__:
|
DEFAULT_LOG_LEVEL = "INFO"
|
||||||
island_args = parse_cli_args()
|
|
||||||
|
|
||||||
# This is here in order to catch EVERYTHING, some functions are being called on
|
|
||||||
# imports, so the log init needs to be first.
|
def load_server_config(path):
|
||||||
try:
|
|
||||||
server_config_path = os.path.expanduser(island_args.server_config)
|
|
||||||
with open(server_config_path, "r") as f:
|
with open(server_config_path, "r") as f:
|
||||||
config_content = f.read()
|
config_content = f.read()
|
||||||
data = json.loads(config_content)
|
data = json.loads(config_content)
|
||||||
|
@ -27,6 +24,19 @@ if "__main__" == __name__:
|
||||||
)
|
)
|
||||||
log_level = data["log_level"] if "log_level" in data else DEFAULT_LOG_LEVEL
|
log_level = data["log_level"] if "log_level" in data else DEFAULT_LOG_LEVEL
|
||||||
|
|
||||||
|
return data_dir, log_level
|
||||||
|
|
||||||
|
|
||||||
|
if "__main__" == __name__:
|
||||||
|
island_args = parse_cli_args()
|
||||||
|
|
||||||
|
# This is here in order to catch EVERYTHING, some functions are being called on
|
||||||
|
# imports, so the log init needs to be first.
|
||||||
|
try:
|
||||||
|
server_config_path = os.path.expanduser(island_args.server_config)
|
||||||
|
|
||||||
|
data_dir, log_level = load_server_config(server_config_path)
|
||||||
|
|
||||||
setup_logging(data_dir, log_level)
|
setup_logging(data_dir, log_level)
|
||||||
|
|
||||||
except OSError as ex:
|
except OSError as ex:
|
||||||
|
|
|
@ -11,6 +11,4 @@ DEFAULT_DEVELOP_SERVER_CONFIG_PATH = os.path.join(
|
||||||
MONKEY_ISLAND_ABS_PATH, "cc", "server_config.json.develop"
|
MONKEY_ISLAND_ABS_PATH, "cc", "server_config.json.develop"
|
||||||
)
|
)
|
||||||
|
|
||||||
DEFAULT_LOG_LEVEL = "NOTSET"
|
|
||||||
|
|
||||||
DEFAULT_DATA_DIR = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc")
|
DEFAULT_DATA_DIR = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc")
|
||||||
|
|
Loading…
Reference in New Issue