Skip to content

Commit

Permalink
hotfix #91
Browse files Browse the repository at this point in the history
  • Loading branch information
ralequi committed Jan 17, 2025
1 parent aaffe58 commit 450ae08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pySMART/smartctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
#
################################################################
from subprocess import Popen, PIPE
from .utils import SMARTCTL_PATH
from .utils import SMARTCTL_PATH, get_trace_logger
from typing import List, Tuple, Union, Optional

import chardet
import logging
import os

logger = logging.getLogger('pySMART')
logger = get_trace_logger()

os.environ["LANG"] = "C"

Expand Down Expand Up @@ -113,7 +112,11 @@ def generic_call(self, params: List[str], pass_options=False) -> Tuple[List[str]

popen_list.extend(params)

logger.trace("Executing the following cmd: {0}".format(popen_list))
try:
logger.trace("Executing the following cmd: {0}".format(popen_list))
except Exception as e:
logger.debug("Executing the following cmd: {0}".format(popen_list))
logger.debug(f"Exception while printing trace: {e}")

return self._exec(popen_list)

Expand Down
11 changes: 11 additions & 0 deletions pySMART/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ def configure_trace_logging():
if getattr(logging.handlers.logging.getLoggerClass(), 'trace', None) is None:
logging.setLoggerClass(TraceLogger)

def get_trace_logger(name:str='pySMART') -> TraceLogger:
configure_trace_logging()
return logging.getLogger(name)

def log_trace(msg: str, *args, **kwargs):
try:
get_trace_logger().trace(msg, *args, **kwargs)
except Exception as e:
get_trace_logger().debug(f"Exception while logging trace info: {e}")
get_trace_logger().debug(msg, *args, **kwargs)


def any_in(search_in, *searched_items):
"""
Expand Down

0 comments on commit 450ae08

Please sign in to comment.