2017-04-09 14:14:04 +03:00
|
|
|
import sys
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
2017-04-12 11:35:07 +03:00
|
|
|
# Find the logging level
|
|
|
|
level = logging.NOTSET
|
2017-04-09 14:14:04 +03:00
|
|
|
for arg in sys.argv:
|
|
|
|
if arg.startswith('--telethon-log='):
|
2017-04-12 11:35:07 +03:00
|
|
|
level = getattr(logging, arg.split('=')[1], logging.NOTSET)
|
|
|
|
break
|
2017-04-09 14:14:04 +03:00
|
|
|
|
2017-04-12 11:35:07 +03:00
|
|
|
# "[Time/Thread] Level: Messages"
|
|
|
|
formatter = logging.Formatter(
|
|
|
|
fmt='[%(asctime)s.%(msecs)03d/%(threadName)s] %(levelname)s: %(message)s',
|
|
|
|
datefmt='%H:%M:%S')
|
2017-04-09 14:14:04 +03:00
|
|
|
|
2017-04-12 11:35:07 +03:00
|
|
|
# Create our logger
|
|
|
|
Log = logging.getLogger('TelethonLogger')
|
|
|
|
Log.setLevel(level)
|
2017-04-09 14:14:04 +03:00
|
|
|
|
2017-04-12 11:35:07 +03:00
|
|
|
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
|