Skip to content

Commit f84c8fa

Browse files
authored
Add files via upload
1 parent 20a312c commit f84c8fa

1 file changed

Lines changed: 82 additions & 18 deletions

File tree

pyarchivefile.py

Lines changed: 82 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -771,31 +771,95 @@ def _get(section_dict, key, default=None):
771771
scrcmd.wait()
772772

773773

774-
def VerbosePrintOut(dbgtxt, outtype="log", dbgenable=True, dgblevel=20):
775-
if(not dbgenable):
776-
return True
777-
log_functions = {
778-
"print": print,
779-
"log": logging.info,
780-
"warning": logging.warning,
781-
"error": logging.error,
782-
"critical": logging.critical,
783-
"exception": logging.exception,
784-
"logalt": lambda x: logging.log(dgblevel, x),
785-
"debug": logging.debug
786-
}
787-
log_function = log_functions.get(outtype)
788-
if(log_function):
789-
log_function(dbgtxt)
774+
# Use a module logger instead of the root logger
775+
_logger = logging.getLogger(__name__)
776+
777+
# Map common level names (case-insensitive) to numeric levels
778+
_LEVEL_BY_NAME = {
779+
"debug": logging.DEBUG,
780+
"info": logging.INFO,
781+
"warning": logging.WARNING,
782+
"error": logging.ERROR,
783+
"critical": logging.CRITICAL,
784+
}
785+
786+
def VerbosePrintOut(dbgtxt, outtype="log", dbgenable=True, dgblevel=20, **kwargs):
787+
"""
788+
Python 2/3-safe logging switchboard.
789+
790+
Args:
791+
dbgtxt: message to emit (any object; coerced to text).
792+
outtype: 'print', a level name (info/warning/error/critical/debug),
793+
an ALL-CAPS logging constant name ('INFO', 'WARNING', ...),
794+
an integer level, or 'log' to use dgblevel.
795+
dbgenable: if False, skip emitting and return False.
796+
dgblevel: numeric level used when outtype is 'log' or unmapped.
797+
**kwargs: passed to logging (e.g., exc_info=True, stacklevel=2, extra=...).
798+
799+
Returns:
800+
True if something was emitted; False otherwise.
801+
"""
802+
if not dbgenable:
803+
return False
804+
805+
logger = kwargs.pop("logger", None) or _logger
806+
msg = _to_text(dbgtxt)
807+
808+
# Normalize outtype
809+
lvl = None
810+
if isinstance(outtype, int):
811+
lvl = outtype
812+
route = "logging"
813+
else:
814+
name = (outtype or "log")
815+
if isinstance(name, string_types):
816+
name_l = name.lower()
817+
if name_l == "print":
818+
print(msg)
819+
return True
820+
if name_l in _LEVEL_BY_NAME:
821+
lvl = _LEVEL_BY_NAME[name_l]
822+
route = "logging"
823+
elif name.isupper() and hasattr(logging, name):
824+
# Accept 'INFO', 'WARNING', etc.
825+
lvl = getattr(logging, name)
826+
route = "logging"
827+
elif name_l in ("log", "logalt"):
828+
lvl = int(dgblevel)
829+
route = "logging"
830+
elif name_l == "exception":
831+
# Safer: only include exc_info if the caller asked for it
832+
lvl = logging.ERROR
833+
kwargs.setdefault("exc_info", True)
834+
route = "logging"
835+
else:
836+
# Unknown string → fall back to dgblevel
837+
lvl = int(dgblevel)
838+
route = "logging"
839+
else:
840+
# Unknown type → fallback
841+
lvl = int(dgblevel)
842+
route = "logging"
843+
844+
if route == "logging":
845+
if not logger.isEnabledFor(lvl):
846+
return False
847+
logger.log(lvl, msg, **kwargs)
790848
return True
849+
791850
return False
792851

793852

794-
def VerbosePrintOutReturn(dbgtxt, outtype="log", dbgenable=True, dgblevel=20):
795-
VerbosePrintOut(dbgtxt, outtype, dbgenable, dgblevel)
853+
def VerbosePrintOutReturn(dbgtxt, outtype="log", dbgenable=True, dgblevel=20, **kwargs):
854+
"""
855+
Log/print dbgtxt (per VerbosePrintOut) and return dbgtxt unchanged.
856+
Useful for tap-style debugging in pipelines.
857+
"""
858+
VerbosePrintOut(dbgtxt, outtype, dbgenable, dgblevel, **kwargs)
796859
return dbgtxt
797860

798861

862+
799863
def _split_posix(path_text):
800864
"""Split POSIX paths regardless of OS; return list of components."""
801865
# Normalize leading './'

0 commit comments

Comments
 (0)