From 13568605911afc74408214cfb6ec2350fec7d0ca Mon Sep 17 00:00:00 2001 From: Adrian Sevcenco Date: Wed, 22 Nov 2023 14:56:42 +0200 Subject: [PATCH] fix import order for logging subsystem --- alienpy/alien.py | 11 +++++------ alienpy/connect_ssl.py | 4 ++-- alienpy/global_vars.py | 3 --- alienpy/setup_cwd.py | 3 ++- alienpy/setup_logging.py | 2 ++ alienpy/tools_nowb.py | 4 ++-- alienpy/wb_api.py | 4 ++-- alienpy/wb_async.py | 4 ++-- alienpy/xrd_core.py | 4 ++-- alienpy/xrd_tools.py | 4 ++-- 10 files changed, 21 insertions(+), 22 deletions(-) diff --git a/alienpy/alien.py b/alienpy/alien.py index 89c4a0c..7899547 100755 --- a/alienpy/alien.py +++ b/alienpy/alien.py @@ -41,14 +41,15 @@ def shlex_join(split_command: list) -> str: return ' '.join(shlex.quote(arg) for ############################################################### ## IMPORT ALIENPY SUB-MODULES +## START LOGGING BEFORE ANYTHING ELSE +from .setup_logging import print_err, print_out, setup_logging, DEBUG, DEBUG_FILE +setup_logging(bool(DEBUG), DEBUG_FILE) # Initialize logging ## IMPORT VERSION STRINGS from .version import ALIENPY_VERSION_DATE, ALIENPY_VERSION_HASH, ALIENPY_VERSION_STR ## IMPORT DATA STRUCTURES from .data_structs import RET ## IMPORT GLOBAL VARIABLES -from .global_vars import ALIENPY_EXECUTABLE, ALIENPY_GLOBAL_WB, AlienSessionInfo, COLORS, DEBUG, DEBUG_FILE, TOKENCERT_NAME, cmds_split, lfn_prefix_re, specs_split -## START LOGGING BEFORE ANYTHING ELSE -from .setup_logging import print_err, print_out, setup_logging +from .global_vars import ALIENPY_EXECUTABLE, ALIENPY_GLOBAL_WB, AlienSessionInfo, COLORS, TOKENCERT_NAME, cmds_split, lfn_prefix_re, specs_split ## ASYNCIO MECHANICS from .wb_api import InitConnection, SendMsg, cd, get_help_srv, retf_print, token_regen, wb_ping ## SSL RELATED VARIABLES: TOKEN AND CERT NAMES @@ -74,9 +75,6 @@ def shlex_join(split_command: list) -> str: return ' '.join(shlex.quote(arg) for session_id = None # variable used to keep a session ID -# Initialize logging -setup_logging(bool(DEBUG), DEBUG_FILE) - # Global XRootD preferences xrd_config_init() @@ -1898,6 +1896,7 @@ def main() -> None: if DEBUG_ARG: os.environ['ALIENPY_DEBUG'] = '1' DEBUG = '1' + logging.getLogger().setLevel(logging.DEBUG) DEBUGFILE_ARG = get_arg_value(sys.argv, '-debugfile') if DEBUGFILE_ARG: diff --git a/alienpy/connect_ssl.py b/alienpy/connect_ssl.py index 2df4608..d2d562c 100644 --- a/alienpy/connect_ssl.py +++ b/alienpy/connect_ssl.py @@ -27,10 +27,10 @@ sys.exit(1) ## GLOBALS +from .setup_logging import print_err, DEBUG, DEBUG_FILE from .data_structs import CertsInfo, RET -from .global_vars import AlienSessionInfo, COLORS, DEBUG, DEBUG_FILE, TOKENCERT_NAME, TOKENKEY_NAME, USERCERT_NAME, USERKEY_NAME, USER_HOME +from .global_vars import AlienSessionInfo, COLORS, TOKENCERT_NAME, TOKENKEY_NAME, USERCERT_NAME, USERKEY_NAME, USER_HOME from .tools_nowb import PrintColor, path_readable -from .setup_logging import print_err def get_ca_path() -> str: diff --git a/alienpy/global_vars.py b/alienpy/global_vars.py index 88d5621..a3c4324 100644 --- a/alienpy/global_vars.py +++ b/alienpy/global_vars.py @@ -65,9 +65,6 @@ def get_certs_names() -> CertsInfo: TIME_CONNECT = os.getenv('ALIENPY_TIMECONNECT', '') DEBUG_TIMING = os.getenv('ALIENPY_TIMING', '') # enable really detailed timings in logs -DEBUG = os.getenv('ALIENPY_DEBUG', '') -DEBUG_FILE = os.getenv('ALIENPY_DEBUG_FILE', f'{USER_HOME}/alien_py.log') - REGEX_PATTERN_TYPE = type(re.compile('.')) guid_regex = re.compile('[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}', re.IGNORECASE) # regex for identification of GUIDs cmds_split = re.compile(';|\n') # regex for spliting chained commands diff --git a/alienpy/setup_cwd.py b/alienpy/setup_cwd.py index d9736c3..9a8642e 100644 --- a/alienpy/setup_cwd.py +++ b/alienpy/setup_cwd.py @@ -4,7 +4,8 @@ import logging import sys -from .global_vars import AlienSessionInfo, DEBUG +from .setup_logging import DEBUG +from .global_vars import AlienSessionInfo from .tools_nowb import read_conf_file from .wb_api import cd diff --git a/alienpy/setup_logging.py b/alienpy/setup_logging.py index 8576fe6..027d713 100644 --- a/alienpy/setup_logging.py +++ b/alienpy/setup_logging.py @@ -10,6 +10,8 @@ ### ENABLE LOGGING BEFORE ANYTHIN ELSE ############################################# +DEBUG = os.getenv('ALIENPY_DEBUG', '') +DEBUG_FILE = os.getenv('ALIENPY_DEBUG_FILE', f'{USER_HOME}/alien_py.log') def print_out(msg: str, toLog: bool = False) -> None: """wrapper for print/log to stdout""" diff --git a/alienpy/tools_nowb.py b/alienpy/tools_nowb.py index 6845c63..269d3b2 100644 --- a/alienpy/tools_nowb.py +++ b/alienpy/tools_nowb.py @@ -23,8 +23,8 @@ import xml.dom.minidom as MD # nosec B408:blacklist from .data_structs import ALIEN_COLLECTION_EL, KV, RET, STAT_FILEPATH -from .global_vars import ALIENPY_FANCY_PRINT, AlienSessionInfo, COLORS, DEBUG, HAS_COLOR, REGEX_PATTERN_TYPE, TMPDIR, USER_HOME, emptyline_re, guid_regex, ignore_comments_re, lfn_prefix_re, rich_print_json -from .setup_logging import print_err, print_out +from .global_vars import ALIENPY_FANCY_PRINT, AlienSessionInfo, COLORS, HAS_COLOR, REGEX_PATTERN_TYPE, TMPDIR, USER_HOME, emptyline_re, guid_regex, ignore_comments_re, lfn_prefix_re, rich_print_json +from .setup_logging import print_err, print_out, DEBUG from .tools_shell import is_cmd, runShellCMD diff --git a/alienpy/wb_api.py b/alienpy/wb_api.py index ecb8bee..e4f6c46 100644 --- a/alienpy/wb_api.py +++ b/alienpy/wb_api.py @@ -19,8 +19,8 @@ from websockets import WebSocketClientProtocol from .data_structs import RET -from .global_vars import ALIENPY_GLOBAL_WB, AlienSessionInfo, DEBUG, DEBUG_FILE, DEBUG_TIMING, TIME_CONNECT, TMPDIR, get_certs_names -from .setup_logging import print_err, print_out +from .setup_logging import print_err, print_out, DEBUG, DEBUG_FILE +from .global_vars import ALIENPY_GLOBAL_WB, AlienSessionInfo, DEBUG_TIMING, TIME_CONNECT, TMPDIR, get_certs_names from .async_tools import syncify from .wb_async import IsWbConnected, wb_close, wb_create, wb_sendmsg, wb_sendmsg_multi from .tools_nowb import CreateJsonCommand, PrintDict, deltat_ms_perf, deltat_us_perf, isReachable, is_help, is_my_pid, path_readable, read_conf_file, writePidFile diff --git a/alienpy/wb_async.py b/alienpy/wb_async.py index a5dde0f..52555a2 100644 --- a/alienpy/wb_async.py +++ b/alienpy/wb_async.py @@ -25,9 +25,9 @@ sys.exit(1) from .version import ALIENPY_VERSION_STR -from .global_vars import DEBUG, DEBUG_FILE, DEBUG_TIMING, TMPDIR +from .setup_logging import print_err, DEBUG, DEBUG_FILE +from .global_vars import DEBUG_TIMING, TMPDIR from .tools_nowb import deltat_ms_perf -from .setup_logging import print_err from .connect_ssl import create_ssl_context, renewCredFilesInfo from .async_tools import start_asyncio, syncify diff --git a/alienpy/xrd_core.py b/alienpy/xrd_core.py index f6d30fa..a7ff782 100644 --- a/alienpy/xrd_core.py +++ b/alienpy/xrd_core.py @@ -17,9 +17,9 @@ from typing import Union from .version import ALIENPY_VERSION_STR +from .setup_logging import print_err, print_out, DEBUG, DEBUG_FILE from .data_structs import CommitInfo, CopyFile, RET, XrdCpArgs, lfn2file -from .global_vars import AlienSessionInfo, COLORS, DEBUG, DEBUG_FILE, REGEX_PATTERN_TYPE, specs_split -from .setup_logging import print_err, print_out +from .global_vars import AlienSessionInfo, COLORS, REGEX_PATTERN_TYPE, specs_split from .wb_api import SendMsg, retf_print from .tools_nowb import (GetHumanReadableSize, PrintColor, common_path, create_metafile, deltat_ms_perf, fileIsValid, fileline2list, format_dst_fn, get_arg, get_arg_value, get_hash_meta, get_lfn_key, get_lfn_name, get_size_meta, diff --git a/alienpy/xrd_tools.py b/alienpy/xrd_tools.py index 9405e96..71ea482 100644 --- a/alienpy/xrd_tools.py +++ b/alienpy/xrd_tools.py @@ -9,8 +9,8 @@ import logging from .data_structs import CommitInfo, RET, STAT_FILEPATH, lfn2file -from .global_vars import AlienSessionInfo, COLORS, DEBUG, REGEX_PATTERN_TYPE, lfn_prefix_re, specs_split -from .setup_logging import print_err +from .setup_logging import print_err, DEBUG +from .global_vars import AlienSessionInfo, COLORS, REGEX_PATTERN_TYPE, lfn_prefix_re, specs_split from .wb_api import SendMsg, SendMsgMulti, retf_print from .tools_nowb import CreateJsonCommand, PrintColor, create_metafile, filter_file_prop, get_arg, get_arg_value, get_lfn_key, make_tmp_fn, valid_regex