summaryrefslogtreecommitdiff
path: root/websockify/websocketproxy.py
diff options
context:
space:
mode:
authorMiguel Xavier Penha Neto <mxp@pinhaotec.com>2015-10-15 10:40:53 -0300
committerMiguel Xavier Penha Neto <mxp@pinhaotec.com>2015-12-01 15:25:17 -0200
commitd947fb6e3052efef3aa2bc4f680912407d79696a (patch)
tree87af6681245de786c3df5231e3177543eee79f64 /websockify/websocketproxy.py
parent8dacbc974cb5a49dd7cddbcfbd1966d1dbbd700f (diff)
downloadwebsockify-d947fb6e3052efef3aa2bc4f680912407d79696a.tar.gz
Add support for log files
Override log_message in websocket.py so messages from send_error are properly saved into the log files Closes #204
Diffstat (limited to 'websockify/websocketproxy.py')
-rwxr-xr-xwebsockify/websocketproxy.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/websockify/websocketproxy.py b/websockify/websocketproxy.py
index 46ab545..c098023 100755
--- a/websockify/websocketproxy.py
+++ b/websockify/websocketproxy.py
@@ -411,9 +411,22 @@ def websockify_init():
help="Automatically respond to ping frames with a pong")
parser.add_option("--heartbeat", type=int, default=0,
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()
+ 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:
logging.getLogger(WebSocketProxy.log_prefix).setLevel(logging.DEBUG)