inspy-logger 3.0.dev3__tar.gz → 3.0.dev4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: inspy-logger
3
- Version: 3.0.dev3
3
+ Version: 3.0.dev4
4
4
  Summary: Colorable, scalable logger for CLI
5
5
  Home-page: https://github.com/Inspyre-Softworks/inSPy-Logger
6
6
  License: MIT
@@ -68,7 +68,7 @@ def get_version_info():
68
68
  table.add_row('Full Version Name', get_full_version_name())
69
69
 
70
70
  if pypi_info.update_available:
71
- table.add_row('Update Available', f'[bold green]Yes[/bold green]')
71
+ table.add_row('Update Available', '[bold green]Yes[/bold green]')
72
72
  table.add_row('Latest Version', f'{pypi_info.new_version_available_num}')
73
73
 
74
74
  table.add_row('Python Executable Path', sys.executable)
@@ -80,10 +80,7 @@ def get_version_info():
80
80
 
81
81
  def main():
82
82
 
83
- if parsed_args.subcommand == 'update':
84
- return update()
85
-
86
- return get_version_info()
83
+ return update() if parsed_args.subcommand == 'update' else get_version_info()
87
84
 
88
85
 
89
86
 
@@ -11,9 +11,10 @@ Since:
11
11
  v2.1.1
12
12
 
13
13
  """
14
+ from inspy_logger.version import parse_version
14
15
 
15
16
  __prog__ = 'inSPy-Logger'
16
- __version__ = '3.0-dev.1'
17
+ __version__ = parse_version()
17
18
  __authors__ = [
18
19
  ('Inspyre-Softworks', 'https://inspyre.tech'),
19
20
  ('Taylor-Jayde Blackstone', '<t.blackstone@inspyre.tech')
@@ -6,7 +6,6 @@ from rich.logging import RichHandler
6
6
  from inspy_logger.__about__ import __prog__ as PROG_NAME
7
7
  from inspy_logger.helpers import find_variable_in_call_stack
8
8
 
9
-
10
9
  # Let's set up some constants.
11
10
  LEVEL_MAP = [
12
11
  ('debug', logging.DEBUG),
@@ -40,11 +39,17 @@ class Logger:
40
39
  A Singleton class responsible for managing the logging mechanisms of the application.
41
40
  """
42
41
 
43
- instances = {}
42
+ instances = {} # A dictionary to hold instances of the Logger class.
44
43
 
45
44
  def __new__(cls, name, *args, **kwargs):
46
45
  """
47
46
  Creates or returns an existing instance of the Logger class for the provided name.
47
+
48
+ Args:
49
+ name (str): The name of the logger instance.
50
+
51
+ Returns:
52
+ Logger: An instance of the Logger class.
48
53
  """
49
54
 
50
55
  if name not in cls.instances:
@@ -54,15 +59,22 @@ class Logger:
54
59
  return cls.instances[name]
55
60
 
56
61
  def __init__(
57
- self,
58
- name,
59
- console_level=DEFAULT_LOGGING_LEVEL,
60
- file_level=logging.DEBUG,
61
- filename="app.log",
62
- parent=None,
62
+ self,
63
+ name,
64
+ console_level=DEFAULT_LOGGING_LEVEL,
65
+ file_level=logging.DEBUG,
66
+ filename="app.log",
67
+ parent=None,
63
68
  ):
64
69
  """
65
70
  Initializes a logger instance.
71
+
72
+ Args:
73
+ name (str): The name of the logger instance.
74
+ console_level (str, optional): The logging level for the console. Defaults to DEFAULT_LOGGING_LEVEL.
75
+ file_level (str, optional): The logging level for the file. Defaults to logging.DEBUG.
76
+ filename (str, optional): The name of the log file. Defaults to "app.log".
77
+ parent (Logger, optional): The parent logger instance. Defaults to None.
66
78
  """
67
79
 
68
80
  if not hasattr(self, "logger"):
@@ -93,10 +105,22 @@ class Logger:
93
105
 
94
106
  @property
95
107
  def device(self):
108
+ """
109
+ Returns the logger instance.
110
+
111
+ Returns:
112
+ Logger: The logger instance.
113
+ """
96
114
  return self.logger
97
115
 
98
116
  @property
99
117
  def name(self):
118
+ """
119
+ Returns the name of the logger instance.
120
+
121
+ Returns:
122
+ str: The name of the logger instance.
123
+ """
100
124
  return self.logger.name
101
125
 
102
126
  def set_up_console(self):
@@ -181,6 +205,18 @@ class Logger:
181
205
  return self.parent
182
206
 
183
207
  def find_child_by_name(self, name: str, case_sensitive=True, exact_match=False):
208
+ """
209
+ Searches for a child logger by its name.
210
+
211
+ Args:
212
+ name (str): The name of the child logger to search for.
213
+ case_sensitive (bool, optional): Whether the search should be case sensitive. Defaults to True.
214
+ exact_match (bool, optional): Whether the search should only return exact matches. Defaults to False.
215
+
216
+ Returns:
217
+ list or Logger: If exact_match is True, returns the Logger instance if found, else returns an empty list.
218
+ If exact_match is False, returns a list of Logger instances whose names contain the search term.
219
+ """
184
220
  self.logger.debug(f'Searching for child with name: {name}')
185
221
  results = []
186
222
 
@@ -197,17 +233,41 @@ class Logger:
197
233
  return results
198
234
 
199
235
  def debug(self, message):
200
- self.logger.debug(message)
236
+ """
237
+ Logs a debug message.
238
+
239
+ Args:
240
+ message (str): The message to log.
241
+ """
242
+ self._log(logging.DEBUG, message, args=(), stacklevel=2)
243
+
201
244
 
202
245
  def info(self, message):
203
- self.logger.info(message)
246
+ """
247
+ Logs an info message.
248
+
249
+ Args:
250
+ message (str): The message to log.
251
+ """
252
+ self._log(logging.INFO, message, args=(), stacklevel=2)
204
253
 
205
254
  def warning(self, message):
206
- self.logger.warning(message)
255
+ """
256
+ Logs a warning message.
257
+
258
+ Args:
259
+ message (str): The message to log.
260
+ """
261
+ self._log(logging.WARNING, message, args=(), stacklevel=2)
207
262
 
208
263
  def error(self, message):
209
- self.logger.error(message)
264
+ """
265
+ Logs an error message.
210
266
 
267
+ Args:
268
+ message (str): The message to log.
269
+ """
270
+ self._log(logging.ERROR, message, args=(), stacklevel=2)
211
271
 
212
272
  def __repr__(self):
213
273
  name = self.name
@@ -224,7 +284,6 @@ class Logger:
224
284
 
225
285
  return f'<Logger: {name} w/ level {self.logger.level} at {hex_id}{parent_part}>'
226
286
 
227
-
228
287
  @classmethod
229
288
  def create_logger_for_caller(cls):
230
289
  """
@@ -234,12 +293,7 @@ class Logger:
234
293
  Logger: An instance of the Logger class for the calling module.
235
294
  """
236
295
  frame = inspect.currentframe().f_back
237
- #print(frame)
238
- #print(dir(frame))
239
- #print(dir(inspect.getmodule(frame)))
240
- #print(inspect.getmodule(frame).__name__)
241
- module_path = cls._determine_module_path(frame)
242
- if module_path:
296
+ if module_path := cls._determine_module_path(frame):
243
297
  return cls(module_path)
244
298
  else:
245
299
  raise ValueError("Unable to determine module path for logger creation.")
@@ -250,24 +304,29 @@ class Logger:
250
304
  Determines the in-project path of the module from the call frame.
251
305
 
252
306
  Args:
253
- frame: The frame from which to determine the module path.
307
+ frame:
308
+ The frame from which to determine the module path.
254
309
 
255
310
  Returns:
256
- str: The in-project path of the module.
311
+ str:
312
+ The in-project path of the module.
257
313
  """
258
- module = inspect.getmodule(frame)
259
- if module:
314
+ if module := inspect.getmodule(frame):
260
315
  base_path = os.path.dirname(os.path.abspath(module.__file__))
261
316
  relative_path = os.path.relpath(frame.f_code.co_filename, base_path)
262
- module_path = relative_path.replace(os.path.sep, '.').rstrip('.py')
263
- return module_path
317
+ return relative_path.replace(os.path.sep, '.').rstrip('.py')
264
318
  return None
265
319
 
320
+ def _log(self, level, msg, args, exc_info=None, extra=None, stack_info=False, stacklevel=1):
321
+ """
322
+ Low-level logging implementation, passing stacklevel to findCaller.
323
+ """
324
+ if self.logger.isEnabledFor(level):
325
+ self.logger._log(level, msg, args, exc_info, extra, stack_info, stacklevel + 1)
266
326
 
267
327
 
268
328
  found_level = find_variable_in_call_stack('INSPY_LOG_LEVEL', DEFAULT_LOGGING_LEVEL)
269
329
 
270
-
271
330
  LOG_DEVICE = Logger(PROG_NAME, found_level)
272
331
  MOD_LOG_DEVICE = LOG_DEVICE.get_child("log_engine", found_level)
273
332
  MOD_LOGGER = MOD_LOG_DEVICE.logger
@@ -16,7 +16,7 @@ __VERSION__ = {
16
16
  'minor': 0,
17
17
  'patch': 0,
18
18
  'release': 'dev',
19
- 'release_num': 3
19
+ 'release_num': 4
20
20
  }
21
21
 
22
22
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "inspy-logger"
3
- version = "3.0-dev.3"
3
+ version = "3.0-dev.4"
4
4
  description = "Colorable, scalable logger for CLI"
5
5
  authors = ["Taylor-Jayde Blackstone <tayjaybabee@gmail.com>"]
6
6
  homepage = 'https://github.com/Inspyre-Softworks/inSPy-Logger'