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
|
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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user