2626
2727from .modules .internal .colors import blue , cyan , green , magenta , red , yellow
2828
29+ LOGGER = logging .getLogger ("chepy" )
30+
2931
3032class ChepyDecorators (object ):
3133 """A class to house all the decorators for Chepy"""
@@ -56,7 +58,7 @@ def call_stack(func, *args, **kwargs):
5658 def is_stdout (func , * args , ** kwargs ): # pragma: no cover
5759 """Detect if method is being called from the cli"""
5860 if sys .stdout .isatty ():
59- logging .warning (f"{ func .__name__ } may not work as expected on the cli" )
61+ LOGGER .warning (f"{ func .__name__ } may not work as expected on the cli" )
6062 return func (* args , ** kwargs )
6163
6264
@@ -99,15 +101,8 @@ def __init__(self, *data):
99101 self ._stack = list ()
100102 #: Holds register values
101103 self ._registers = dict ()
102-
103- #: Log level
104- self .log_level = logging .INFO
105- #: Log format message
106- self .log_format = "%(levelname)-2s - %(message)s"
107- logging .getLogger ().setLevel (self .log_level )
108- logging .basicConfig (format = self .log_format )
109104 # logger
110- self ._log = logging
105+ self ._log = LOGGER
111106
112107 @property
113108 def recipe (self ) -> List [Dict [str , Union [str , Dict [str , Any ]]]]:
@@ -136,7 +131,7 @@ def __str__(self):
136131 except UnicodeDecodeError : # pragma: no cover
137132 return "Could not convert to str, but the data exists in the states. Use o, output or out() to access the values"
138133 except : # pragma: no cover
139- logging .exception (
134+ self . _log .exception (
140135 "\n \n Cannot print current state. Either chain with "
141136 "another method, or use one of the output methods "
142137 "Example: .o, .out, or .state\n \n "
@@ -186,7 +181,7 @@ def _info_logger(self, data: str) -> None:
186181 Returns:
187182 Chepy: The Chepy object.
188183 """
189- logging .info (blue (data ))
184+ self . _log .info (blue (data ))
190185 return None
191186
192187 def _warning_logger (self , data : str ) -> None : # pragma: no cover
@@ -198,7 +193,7 @@ def _warning_logger(self, data: str) -> None: # pragma: no cover
198193 Returns:
199194 Chepy: The Chepy object.
200195 """
201- logging .warning (yellow (data ))
196+ self . _log .warning (yellow (data ))
202197 return None
203198
204199 def _error_logger (self , data : str ) -> None : # pragma: no cover
@@ -210,7 +205,7 @@ def _error_logger(self, data: str) -> None: # pragma: no cover
210205 Returns:
211206 Chepy: The Chepy object.
212207 """
213- logging .error (red (data ))
208+ self . _log .error (red (data ))
214209 return None
215210
216211 def subsection (
@@ -463,7 +458,7 @@ def delete_state(self, index: int):
463458 try :
464459 del self .states [index ]
465460 except KeyError : # pragma: no cover
466- logging .warning ("{} does not exist" .format (index ))
461+ self . _log .warning ("{} does not exist" .format (index ))
467462 return self
468463
469464 @ChepyDecorators .call_stack
@@ -541,7 +536,7 @@ def delete_buffer(self, index: int):
541536 try :
542537 del self .buffers [index ]
543538 except KeyError : # pragma: no cover
544- logging .warning ("{} does not exist" .format (index ))
539+ self . _log .warning ("{} does not exist" .format (index ))
545540 return self
546541
547542 @ChepyDecorators .call_stack
@@ -1520,7 +1515,7 @@ def cb(data):
15201515 """
15211516 # dont run if from cli
15221517 if sys .stdout .isatty (): # pragma: no cover
1523- logging .warning ("callback cannot be used via the cli" )
1518+ self . _log .warning ("callback cannot be used via the cli" )
15241519 return self
15251520 self .state = callback_function (self .state )
15261521 return self
@@ -1702,7 +1697,7 @@ def search_dir(self, pattern: Union[bytes, str]):
17021697 rgx = re .compile (self ._str_to_bytes (pattern ), flags = re .I )
17031698 hold = []
17041699 for path in Path (paths ).glob ("**/*" ):
1705- if path .is_dir (): # pragma: no cover
1700+ if path .is_dir (): # pragma: no cover
17061701 continue
17071702 data = path .read_bytes ()
17081703 matched = rgx .findall (data )
0 commit comments