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
# 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

View File

@ -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)