aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-10-09 16:39:29 -0700
committerbnewbold <bnewbold@robocracy.org>2016-10-09 16:39:29 -0700
commitd166efbdfa85cdcf8450a2b7c2d3da3b2c4fa82a (patch)
tree5c87e7401903b7857b6b53f3cc89ea56fe677b3f /examples
parent89f2f02ab813fe19fd029e95f6a2f6ce65c5a16b (diff)
downloadeinhyrningsins-d166efbdfa85cdcf8450a2b7c2d3da3b2c4fa82a.tar.gz
einhyrningsins-d166efbdfa85cdcf8450a2b7c2d3da3b2c4fa82a.zip
use logging in python example
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/einhorn_http.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/examples/einhorn_http.py b/examples/einhorn_http.py
index 304d01a..5c9a680 100755
--- a/examples/einhorn_http.py
+++ b/examples/einhorn_http.py
@@ -12,6 +12,7 @@ import sys
import socket
import socketserver
import http.server
+import logging as log
class EinhornTCPServer(socketserver.TCPServer):
@@ -21,7 +22,7 @@ class EinhornTCPServer(socketserver.TCPServer):
# Try to sniff first socket
try:
fd = int(os.environ['EINHORN_FD_0'])
- print("Will try to listen with fd=%d" % fd)
+ log.debug("Will try to listen with fd=%d" % fd)
except KeyError:
raise EnvironmentError("Couldn't find EINHORN_FD_0 env variable... is this running under einhorn?")
@@ -36,17 +37,20 @@ class EinhornTCPServer(socketserver.TCPServer):
raise
if __name__ == "__main__":
+ log.basicConfig(
+ format="%(filename)s [%(process)d] %(levelname)s: %(message)s",
+ level=log.DEBUG)
Handler = http.server.SimpleHTTPRequestHandler
try:
httpd = EinhornTCPServer(None, Handler)
except EnvironmentError as ee:
- print(ee)
- print("Falling back on vanilla http server on 8080")
+ log.warn(str(ee))
+ log.info("Falling back on vanilla http server on 8080")
httpd = socketserver.TCPServer(("localhost", 8080), Handler)
- print("Serving!")
+ log.debug("Serving!")
try:
httpd.serve_forever()
except KeyboardInterrupt:
- print("Caught KeyboardInterrupt, shutting down")
+ log.warn("Caught KeyboardInterrupt, shutting down")
httpd.server_close()