implement utils.print_exception()

Previously we used logging.error(e) and traceback.print_exc()
to output error stack trace. The problem is, we want to
output the stack trace only when verbose > 0. The if statement
scattered around the code. So we replaced them with the new
utils.print_exception() call.
This commit is contained in:
clowwindy 2015-02-10 17:16:24 +08:00
parent 48ddc1714b
commit cb7062e1c1
8 changed files with 32 additions and 29 deletions

View file

@ -23,7 +23,7 @@ import sys
import logging
import signal
import time
from shadowsocks import common
from shadowsocks import common, utils
# this module is ported from ShadowVPN daemon.c
@ -58,7 +58,7 @@ def write_pid_file(pid_file, pid):
fd = os.open(pid_file, os.O_RDWR | os.O_CREAT,
stat.S_IRUSR | stat.S_IWUSR)
except OSError as e:
logging.error(e)
utils.print_exception(e)
return -1
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
assert flags != -1
@ -127,7 +127,7 @@ def daemon_start(pid_file, log_file):
freopen(log_file, 'a', sys.stdout)
freopen(log_file, 'a', sys.stderr)
except IOError as e:
logging.error(e)
utils.print_exception(e)
sys.exit(1)
@ -140,7 +140,7 @@ def daemon_stop(pid_file):
if not buf:
logging.error('not running')
except IOError as e:
logging.error(e)
utils.print_exception(e)
if e.errno == errno.ENOENT:
# always exit 0 if we are sure daemon is not running
logging.error('not running')
@ -155,7 +155,7 @@ def daemon_stop(pid_file):
logging.error('not running')
# always exit 0 if we are sure daemon is not running
return
logging.error(e)
utils.print_exception(e)
sys.exit(1)
else:
logging.error('pid is not positive: %d', pid)