support -vv verbose logging
This commit is contained in:
parent
6c6afde2a5
commit
41010d810e
2 changed files with 18 additions and 7 deletions
|
@ -30,6 +30,7 @@ import traceback
|
||||||
import random
|
import random
|
||||||
import encrypt
|
import encrypt
|
||||||
import eventloop
|
import eventloop
|
||||||
|
import utils
|
||||||
from common import parse_header
|
from common import parse_header
|
||||||
|
|
||||||
|
|
||||||
|
@ -559,7 +560,7 @@ class TCPRelay(object):
|
||||||
# we just need a sorted last_activity queue and it's faster than heapq
|
# we just need a sorted last_activity queue and it's faster than heapq
|
||||||
# in fact we can do O(1) insertion/remove so we invent our own
|
# in fact we can do O(1) insertion/remove so we invent our own
|
||||||
if self._timeouts:
|
if self._timeouts:
|
||||||
logging.debug('sweeping timeouts')
|
logging.log(utils.VERBOSE_LEVEL, 'sweeping timeouts')
|
||||||
now = time.time()
|
now = time.time()
|
||||||
length = len(self._timeouts)
|
length = len(self._timeouts)
|
||||||
pos = self._timeout_offset
|
pos = self._timeout_offset
|
||||||
|
@ -590,9 +591,9 @@ class TCPRelay(object):
|
||||||
|
|
||||||
def _handle_events(self, events):
|
def _handle_events(self, events):
|
||||||
for sock, fd, event in events:
|
for sock, fd, event in events:
|
||||||
# if sock:
|
if sock:
|
||||||
# logging.debug('fd %d %s', fd,
|
logging.log(utils.VERBOSE_LEVEL, 'fd %d %s', fd,
|
||||||
# eventloop.EVENT_NAMES.get(event, event))
|
eventloop.EVENT_NAMES.get(event, event))
|
||||||
if sock == self._server_socket:
|
if sock == self._server_socket:
|
||||||
if event & eventloop.POLL_ERR:
|
if event & eventloop.POLL_ERR:
|
||||||
# TODO
|
# TODO
|
||||||
|
|
|
@ -28,6 +28,9 @@ import getopt
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
VERBOSE_LEVEL = 5
|
||||||
|
|
||||||
|
|
||||||
def check_python():
|
def check_python():
|
||||||
info = sys.version_info
|
info = sys.version_info
|
||||||
if not (info[0] == 2 and info[1] >= 6):
|
if not (info[0] == 2 and info[1] >= 6):
|
||||||
|
@ -106,6 +109,7 @@ def get_config(is_local):
|
||||||
config = {}
|
config = {}
|
||||||
|
|
||||||
optlist, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
|
optlist, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
|
||||||
|
v_count = 0
|
||||||
for key, value in optlist:
|
for key, value in optlist:
|
||||||
if key == '-p':
|
if key == '-p':
|
||||||
config['server_port'] = int(value)
|
config['server_port'] = int(value)
|
||||||
|
@ -120,7 +124,10 @@ def get_config(is_local):
|
||||||
elif key == '-b':
|
elif key == '-b':
|
||||||
config['local_address'] = value
|
config['local_address'] = value
|
||||||
elif key == '-v':
|
elif key == '-v':
|
||||||
config['verbose'] = True
|
v_count += 1
|
||||||
|
print v_count
|
||||||
|
# '-vv' turns on more verbose mode
|
||||||
|
config['verbose'] = v_count
|
||||||
elif key == '-t':
|
elif key == '-t':
|
||||||
config['timeout'] = int(value)
|
config['timeout'] = int(value)
|
||||||
elif key == '--fast-open':
|
elif key == '--fast-open':
|
||||||
|
@ -148,11 +155,14 @@ def get_config(is_local):
|
||||||
config['verbose'] = config.get('verbose', False)
|
config['verbose'] = config.get('verbose', False)
|
||||||
config['local_address'] = config.get('local_address', '127.0.0.1')
|
config['local_address'] = config.get('local_address', '127.0.0.1')
|
||||||
|
|
||||||
if config['verbose']:
|
logging.getLogger('').handlers = []
|
||||||
|
logging.addLevelName(VERBOSE_LEVEL, 'VERBOSE')
|
||||||
|
if config['verbose'] == 2:
|
||||||
|
level = VERBOSE_LEVEL
|
||||||
|
elif config['verbose']:
|
||||||
level = logging.DEBUG
|
level = logging.DEBUG
|
||||||
else:
|
else:
|
||||||
level = logging.INFO
|
level = logging.INFO
|
||||||
logging.getLogger('').handlers = []
|
|
||||||
logging.basicConfig(level=level,
|
logging.basicConfig(level=level,
|
||||||
format='%(asctime)s %(levelname)-8s %(message)s',
|
format='%(asctime)s %(levelname)-8s %(message)s',
|
||||||
datefmt='%Y-%m-%d %H:%M:%S', filemode='a+')
|
datefmt='%Y-%m-%d %H:%M:%S', filemode='a+')
|
||||||
|
|
Loading…
Reference in a new issue