dvlogger 2.0.4__tar.gz → 2.0.6__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.4
3
+ Version: 2.0.6
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.4)
1
+ # dvlogger (v2.0.6)
2
2
 
3
3
  ## Requirements
4
4
 
@@ -17,10 +17,10 @@
17
17
  import logging
18
18
  import dvlogger
19
19
 
20
- dvlogger.setup(level=logging.DEBUG, capture_warnings=True, exception_hook=True, use_tg_handler=False, use_file_handler=False, file_config=None, tg_config=None, log_prefix=None)
20
+ dvlogger.setup(level=logging.DEBUG, capture_warnings=True, exception_hook=True, use_tg_handler=False, use_file_handler=False, file_config=None, tg_config=None, log_prefix="Prod-Shard-G6")
21
21
 
22
22
  dvlogger.tg_send_file(FILE_PATH, 'file_name')
23
- dvlogger.tg_send_file(FILE_OBJECT, 'file_name', 'caption', is_error=True, log_prefix="Prod-Shard-G6")
23
+ dvlogger.tg_send_file(FILE_OBJECT, 'file_name', 'caption', is_error=True)
24
24
  ```
25
25
 
26
26
  ```
@@ -98,7 +98,7 @@ class CustomFormatter(logging.Formatter):
98
98
  return self.FORMATS[record.levelno].format(record)
99
99
 
100
100
  class TGHandler(logging.Handler):
101
- def setup(self, level, level_bypass_prefix, message_skip_prefix, bot_key, chat_id, thread_id, error_chat_id, error_thread_id, flush_interval):
101
+ def setup(self, level, level_bypass_prefix, message_skip_prefix, bot_key, chat_id, thread_id, error_chat_id, error_thread_id, flush_interval, log_prefix):
102
102
  self.level_filter = level
103
103
  self.level_bypass_prefix = level_bypass_prefix
104
104
  self.message_skip_prefix = message_skip_prefix
@@ -108,6 +108,7 @@ class TGHandler(logging.Handler):
108
108
  self.error_chat_id = error_chat_id
109
109
  self.error_thread_id = error_thread_id
110
110
  self.flush_interval = flush_interval / 1000.0
111
+ self.log_prefix = log_prefix
111
112
 
112
113
  for attr in ('chat_id', 'thread_id', 'error_chat_id', 'error_thread_id'):
113
114
  val = getattr(self, attr)
@@ -166,8 +167,8 @@ class TGHandler(logging.Handler):
166
167
  data = f'--{boundary}\r\nContent-Disposition: form-data; name="chat_id"\r\n\r\n{chat_id}\r\n'
167
168
  if thread_id is not None:
168
169
  data += f'--{boundary}\r\nContent-Disposition: form-data; name="message_thread_id"\r\n\r\n{thread_id}\r\n'
169
- if caption:
170
- data += f'--{boundary}\r\nContent-Disposition: form-data; name="caption"\r\n\r\n{caption}\r\n'
170
+ if caption or self.log_prefix:
171
+ data += f'--{boundary}\r\nContent-Disposition: form-data; name="caption"\r\n\r\n{self.log_prefix + " - " if caption else ""}{caption}\r\n'
171
172
  data += (
172
173
  f'--{boundary}\r\n'
173
174
  f'Content-Disposition: form-data; name="document"; filename="{filename}"\r\n'
@@ -184,20 +185,26 @@ class TGHandler(logging.Handler):
184
185
  },
185
186
  )
186
187
 
187
- def send_file(self, file, name, caption='', is_error=False):
188
+ def send_file(self, file, name=None, caption='', is_error=False):
188
189
  chat_id = self.chat_id
189
190
  thread_id = self.thread_id
190
191
  if is_error and self.error_chat_id is not None:
191
192
  chat_id = self.error_chat_id
192
193
  thread_id = self.error_thread_id
194
+ if caption is None:
195
+ caption = ''
193
196
 
194
197
  if isinstance(file, str):
195
198
  with open(file, 'rb') as f:
196
199
  filedata = f.read()
200
+ if name is None:
201
+ name = os.path.basename(file)
197
202
  elif hasattr(file, 'read'):
198
203
  filedata = file.read()
199
204
  if isinstance(filedata, str):
200
205
  filedata = filedata.encode()
206
+ if name is None:
207
+ name = f"{time.time()}.txt"
201
208
  else:
202
209
  logging.error(f'{self.message_skip_prefix}file must be a path (str) or file-like object, got {type(file).__name__}')
203
210
  return None
@@ -408,6 +415,7 @@ def setup(level=logging.DEBUG, capture_warnings=True, exception_hook=True, use_t
408
415
  tg_config.get('error_chat_id', None),
409
416
  tg_config.get('error_thread_id', None),
410
417
  tg_config.get('flush_interval', 5000),
418
+ log_prefix,
411
419
  )
412
420
  TG_HANDLER.setLevel(logging.DEBUG)
413
421
  TG_HANDLER.setFormatter(formatter)
@@ -428,8 +436,9 @@ def setup(level=logging.DEBUG, capture_warnings=True, exception_hook=True, use_t
428
436
 
429
437
  logging.info('*******')
430
438
 
431
- def tg_send_file(file, name, caption='', is_error=False):
432
- TG_HANDLER.send_file(file, name, caption, is_error)
439
+ def tg_send_file(file, name=None, caption='', is_error=False):
440
+ t = threading.Thread(target=TG_HANDLER.send_file, args=(file, name, caption, is_error), daemon=False)
441
+ t.start()
433
442
 
434
443
  TG_HANDLER = TGHandler()
435
444
  CW_HANDLER = CWHandler()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dvlogger
3
- Version: 2.0.4
3
+ Version: 2.0.6
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.4"
7
+ version = "2.0.6"
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