dvlogger 2.0.6__tar.gz → 2.0.8__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.4
2
2
  Name: dvlogger
3
- Version: 2.0.6
3
+ Version: 2.0.8
4
4
  Summary: A custom logger with coloured output and uncaught exception logging. Supports threading and asyncio.
5
5
  Author-email: Pranav Mittal <pranavmittal611@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/mlpranav/dvlogger
@@ -1,4 +1,4 @@
1
- # dvlogger (v2.0.6)
1
+ # dvlogger (v2.0.8)
2
2
 
3
3
  ## Requirements
4
4
 
@@ -23,6 +23,21 @@ dvlogger.tg_send_file(FILE_PATH, 'file_name')
23
23
  dvlogger.tg_send_file(FILE_OBJECT, 'file_name', 'caption', is_error=True)
24
24
  ```
25
25
 
26
+ To skip immediate task-error logging for an expected exception, pass its class:
27
+
28
+ ```python
29
+ class NoAccountsAvailable(Exception):
30
+ pass
31
+
32
+ dvlogger.setup(ignored_task_exceptions=(NoAccountsAvailable,))
33
+ ```
34
+
35
+ These exceptions (including subclasses) still propagate to the awaiting caller.
36
+ All other exceptions keep their normal logging. This option only affects the
37
+ `asyncio.create_task` wrapper; exceptions left unhandled still reach the event
38
+ loop's exception handler. The default `()` preserves existing behavior. Calling
39
+ `setup()` again without this option resets the exclusions.
40
+
26
41
  ```
27
42
  file_config
28
43
  name [os.path.basename(sys.argv[0]).strip(), dvlogger]
@@ -44,9 +44,13 @@ def asyncio_exception_handler(loop, context):
44
44
  logging.error(f'Non-exception asyncio error: {context}')
45
45
  loop.default_exception_handler(context)
46
46
 
47
+ _ignored_task_exceptions = ()
48
+
47
49
  async def asyncio_task_wrapper(coro):
48
50
  try:
49
51
  return await coro
52
+ except _ignored_task_exceptions:
53
+ raise
50
54
  except Exception as e:
51
55
  logging.error('Task exception caught immediately:')
52
56
  sys.excepthook(type(e), e, e.__traceback__)
@@ -241,7 +245,7 @@ class TGHandler(logging.Handler):
241
245
  next_flush = math.ceil(cur_time / self.flush_interval) * self.flush_interval
242
246
  sleep_time = next_flush - cur_time
243
247
  if sleep_time > 0:
244
- time.sleep(sleep_time)
248
+ self.shutdown_event.wait(timeout=sleep_time)
245
249
 
246
250
  log_entries = []
247
251
  while True: # drain queue
@@ -307,8 +311,13 @@ class TGHandler(logging.Handler):
307
311
  class CWHandler:
308
312
  pass # integrate watchtower?
309
313
 
310
- def setup(level=logging.DEBUG, capture_warnings=True, exception_hook=True, use_tg_handler=False, use_file_handler=False, use_cw_handler=False, file_config=None, tg_config=None, cw_config=None, log_prefix=None):
314
+ def setup(level=logging.DEBUG, capture_warnings=True, exception_hook=True, use_tg_handler=False, use_file_handler=False, use_cw_handler=False, file_config=None, tg_config=None, cw_config=None, log_prefix=None, ignored_task_exceptions=()):
311
315
  """
316
+ ignored_task_exceptions [()]
317
+ Tuple of Exception classes that asyncio tasks re-raise without immediate
318
+ logging. Other exceptions keep the normal logging behavior. Unhandled
319
+ exceptions still reach the event loop's exception handler.
320
+
312
321
  file_config
313
322
  name [os.path.basename(sys.argv[0]).strip(), dvlogger]
314
323
  kind [BASIC] # ROTATING, TIMED, BASIC
@@ -345,6 +354,14 @@ def setup(level=logging.DEBUG, capture_warnings=True, exception_hook=True, use_t
345
354
  flush_interval [63000] # ms
346
355
  """
347
356
 
357
+ global _ignored_task_exceptions
358
+ if not isinstance(ignored_task_exceptions, tuple) or any(
359
+ not isinstance(exc, type) or not issubclass(exc, Exception)
360
+ for exc in ignored_task_exceptions
361
+ ):
362
+ raise TypeError('ignored_task_exceptions must be a tuple of Exception classes')
363
+ _ignored_task_exceptions = ignored_task_exceptions
364
+
348
365
  if file_config is None:
349
366
  file_config = {}
350
367
  if cw_config is None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dvlogger
3
- Version: 2.0.6
3
+ Version: 2.0.8
4
4
  Summary: A custom logger with coloured output and uncaught exception logging. Supports threading and asyncio.
5
5
  Author-email: Pranav Mittal <pranavmittal611@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/mlpranav/dvlogger
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "dvlogger"
7
- version = "2.0.6"
7
+ version = "2.0.8"
8
8
  description = "A custom logger with coloured output and uncaught exception logging. Supports threading and asyncio."
9
9
  authors = [
10
10
  {name = "Pranav Mittal", email = "pranavmittal611@gmail.com"},
File without changes
File without changes