Add current time to the log output

This commit is contained in:
Lonami Exo 2017-04-12 10:35:07 +02:00
parent 1d2420d549
commit f6c34f8ba2
2 changed files with 22 additions and 13 deletions

View File

@ -2,20 +2,29 @@ import sys
import logging import logging
# Find the logging level
level = logging.NOTSET
for arg in sys.argv: for arg in sys.argv:
if arg.startswith('--telethon-log='): if arg.startswith('--telethon-log='):
level = getattr(logging, arg.split('=')[1], None) level = getattr(logging, arg.split('=')[1], logging.NOTSET)
if not isinstance(level, int): break
raise ValueError('Invalid log level: %s' % level)
print('Using log level', level, 'which is', arg.split('=')[1])
logging.basicConfig(level=level)
# "[Time/Thread] Level: Messages"
formatter = logging.Formatter(
fmt='[%(asctime)s.%(msecs)03d/%(threadName)s] %(levelname)s: %(message)s',
datefmt='%H:%M:%S')
class Logger: # Create our logger
def __init__(self): Log = logging.getLogger('TelethonLogger')
setattr(self, 'd', logging.debug) Log.setLevel(level)
setattr(self, 'i', logging.info)
setattr(self, 'w', logging.warning)
setattr(self, 'e', logging.error)
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

View File

@ -47,7 +47,7 @@ class MtProtoSender:
self.updates_thread_sleep = None self.updates_thread_sleep = None
self.updates_thread = Thread( 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. # The "updates" thread must also be running to make periodic ping requests.
self.set_updates_thread(running=True) self.set_updates_thread(running=True)