Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion chepy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from pathlib import Path
from configparser import ConfigParser

LOGGER = logging.getLogger("chepy")


class ChepyConfig(object):
def __init__(self):
Expand Down Expand Up @@ -142,5 +144,5 @@ def load_plugins(self): # pragma: no cover
loaded = getattr(plugin, klass)
plugins.append(loaded)
except:
logging.warning(f"Error loading {plugin.__name__}")
LOGGER.warning(f"Error loading {plugin.__name__}")
return plugins
29 changes: 12 additions & 17 deletions chepy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

from .modules.internal.colors import blue, cyan, green, magenta, red, yellow

LOGGER = logging.getLogger("chepy")


class ChepyDecorators(object):
"""A class to house all the decorators for Chepy"""
Expand Down Expand Up @@ -56,7 +58,7 @@ def call_stack(func, *args, **kwargs):
def is_stdout(func, *args, **kwargs): # pragma: no cover
"""Detect if method is being called from the cli"""
if sys.stdout.isatty():
logging.warning(f"{func.__name__} may not work as expected on the cli")
LOGGER.warning(f"{func.__name__} may not work as expected on the cli")
return func(*args, **kwargs)


Expand Down Expand Up @@ -99,15 +101,8 @@ def __init__(self, *data):
self._stack = list()
#: Holds register values
self._registers = dict()

#: Log level
self.log_level = logging.INFO
#: Log format message
self.log_format = "%(levelname)-2s - %(message)s"
logging.getLogger().setLevel(self.log_level)
logging.basicConfig(format=self.log_format)
# logger
self._log = logging
self._log = LOGGER

@property
def recipe(self) -> List[Dict[str, Union[str, Dict[str, Any]]]]:
Expand Down Expand Up @@ -136,7 +131,7 @@ def __str__(self):
except UnicodeDecodeError: # pragma: no cover
return "Could not convert to str, but the data exists in the states. Use o, output or out() to access the values"
except: # pragma: no cover
logging.exception(
self._log.exception(
"\n\nCannot print current state. Either chain with "
"another method, or use one of the output methods "
"Example: .o, .out, or .state\n\n"
Expand Down Expand Up @@ -186,7 +181,7 @@ def _info_logger(self, data: str) -> None:
Returns:
Chepy: The Chepy object.
"""
logging.info(blue(data))
self._log.info(blue(data))
return None

def _warning_logger(self, data: str) -> None: # pragma: no cover
Expand All @@ -198,7 +193,7 @@ def _warning_logger(self, data: str) -> None: # pragma: no cover
Returns:
Chepy: The Chepy object.
"""
logging.warning(yellow(data))
self._log.warning(yellow(data))
return None

def _error_logger(self, data: str) -> None: # pragma: no cover
Expand All @@ -210,7 +205,7 @@ def _error_logger(self, data: str) -> None: # pragma: no cover
Returns:
Chepy: The Chepy object.
"""
logging.error(red(data))
self._log.error(red(data))
return None

def subsection(
Expand Down Expand Up @@ -463,7 +458,7 @@ def delete_state(self, index: int):
try:
del self.states[index]
except KeyError: # pragma: no cover
logging.warning("{} does not exist".format(index))
self._log.warning("{} does not exist".format(index))
return self

@ChepyDecorators.call_stack
Expand Down Expand Up @@ -541,7 +536,7 @@ def delete_buffer(self, index: int):
try:
del self.buffers[index]
except KeyError: # pragma: no cover
logging.warning("{} does not exist".format(index))
self._log.warning("{} does not exist".format(index))
return self

@ChepyDecorators.call_stack
Expand Down Expand Up @@ -1520,7 +1515,7 @@ def cb(data):
"""
# dont run if from cli
if sys.stdout.isatty(): # pragma: no cover
logging.warning("callback cannot be used via the cli")
self._log.warning("callback cannot be used via the cli")
return self
self.state = callback_function(self.state)
return self
Expand Down Expand Up @@ -1702,7 +1697,7 @@ def search_dir(self, pattern: Union[bytes, str]):
rgx = re.compile(self._str_to_bytes(pattern), flags=re.I)
hold = []
for path in Path(paths).glob("**/*"):
if path.is_dir(): # pragma: no cover
if path.is_dir(): # pragma: no cover
continue
data = path.read_bytes()
matched = rgx.findall(data)
Expand Down