Merge pull request #205 from miguelxpn/logfile
Add support for log files
This commit is contained in:
commit
ebe378c6db
|
@ -113,6 +113,9 @@ class WebSocketRequestHandler(SimpleHTTPRequestHandler):
|
||||||
|
|
||||||
SimpleHTTPRequestHandler.__init__(self, req, addr, server)
|
SimpleHTTPRequestHandler.__init__(self, req, addr, server)
|
||||||
|
|
||||||
|
def log_message(self, format, *args):
|
||||||
|
self.logger.info("%s - - [%s] %s" % (self.address_string(), self.log_date_time_string(), format % args))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def unmask(buf, hlen, plen):
|
def unmask(buf, hlen, plen):
|
||||||
pstart = hlen + 4
|
pstart = hlen + 4
|
||||||
|
|
|
@ -411,9 +411,22 @@ def websockify_init():
|
||||||
help="Automatically respond to ping frames with a pong")
|
help="Automatically respond to ping frames with a pong")
|
||||||
parser.add_option("--heartbeat", type=int, default=0,
|
parser.add_option("--heartbeat", type=int, default=0,
|
||||||
help="send a ping to the client every HEARTBEAT seconds")
|
help="send a ping to the client every HEARTBEAT seconds")
|
||||||
|
parser.add_option("--log-file", metavar="FILE",
|
||||||
|
dest="log_file",
|
||||||
|
help="File where logs will be saved")
|
||||||
|
|
||||||
|
|
||||||
(opts, args) = parser.parse_args()
|
(opts, args) = parser.parse_args()
|
||||||
|
|
||||||
|
if opts.log_file:
|
||||||
|
opts.log_file = os.path.abspath(opts.log_file)
|
||||||
|
handler = logging.FileHandler(opts.log_file)
|
||||||
|
handler.setLevel(logging.DEBUG)
|
||||||
|
handler.setFormatter(logging.Formatter("%(message)s"))
|
||||||
|
logging.getLogger(WebSocketProxy.log_prefix).addHandler(handler)
|
||||||
|
|
||||||
|
del opts.log_file
|
||||||
|
|
||||||
if opts.verbose:
|
if opts.verbose:
|
||||||
logging.getLogger(WebSocketProxy.log_prefix).setLevel(logging.DEBUG)
|
logging.getLogger(WebSocketProxy.log_prefix).setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue