mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Add current time to the log output
This commit is contained in:
parent
1d2420d549
commit
f6c34f8ba2
|
@ -2,20 +2,29 @@ import sys
|
|||
import logging
|
||||
|
||||
|
||||
# Find the logging level
|
||||
level = logging.NOTSET
|
||||
for arg in sys.argv:
|
||||
if arg.startswith('--telethon-log='):
|
||||
level = getattr(logging, arg.split('=')[1], None)
|
||||
if not isinstance(level, int):
|
||||
raise ValueError('Invalid log level: %s' % level)
|
||||
print('Using log level', level, 'which is', arg.split('=')[1])
|
||||
logging.basicConfig(level=level)
|
||||
level = getattr(logging, arg.split('=')[1], logging.NOTSET)
|
||||
break
|
||||
|
||||
# "[Time/Thread] Level: Messages"
|
||||
formatter = logging.Formatter(
|
||||
fmt='[%(asctime)s.%(msecs)03d/%(threadName)s] %(levelname)s: %(message)s',
|
||||
datefmt='%H:%M:%S')
|
||||
|
||||
class Logger:
|
||||
def __init__(self):
|
||||
setattr(self, 'd', logging.debug)
|
||||
setattr(self, 'i', logging.info)
|
||||
setattr(self, 'w', logging.warning)
|
||||
setattr(self, 'e', logging.error)
|
||||
# Create our logger
|
||||
Log = logging.getLogger('TelethonLogger')
|
||||
Log.setLevel(level)
|
||||
|
||||
Log = Logger()
|
||||
console = logging.StreamHandler()
|
||||
console.setFormatter(formatter)
|
||||
|
||||
Log.addHandler(console)
|
||||
|
||||
# Use shorter function names
|
||||
Log.__dict__['d'] = Log.debug
|
||||
Log.__dict__['i'] = Log.info
|
||||
Log.__dict__['w'] = Log.warning
|
||||
Log.__dict__['e'] = Log.error
|
||||
|
|
|
@ -47,7 +47,7 @@ class MtProtoSender:
|
|||
self.updates_thread_sleep = None
|
||||
|
||||
self.updates_thread = Thread(
|
||||
target=self.updates_thread_method, name='Updates thread')
|
||||
target=self.updates_thread_method, name='UpdatesThread')
|
||||
|
||||
# The "updates" thread must also be running to make periodic ping requests.
|
||||
self.set_updates_thread(running=True)
|
||||
|
|
Loading…
Reference in New Issue
Block a user