##// END OF EJS Templates
adjustments to notebook app logging...
MinRK -
Show More
@@ -0,0 +1,52 b''
1 #-----------------------------------------------------------------------------
2 # Copyright (C) 2013 The IPython Development Team
3 #
4 # Distributed under the terms of the BSD License. The full license is in
5 # the file COPYING, distributed as part of this software.
6 #-----------------------------------------------------------------------------
7
8 import json
9 from tornado.log import access_log
10
11 def log_request(handler):
12 """log a bit more information about each request than tornado's default
13
14 - move static file get success to debug-level (reduces noise)
15 - get proxied IP instead of proxy IP
16 - log referer for redirect and failed requests
17 - log user-agent for failed requests
18 """
19 status = handler.get_status()
20 request = handler.request
21 if status < 300 or status == 304:
22 # Successes (or 304 FOUND) are debug-level
23 log_method = access_log.debug
24 elif status < 400:
25 log_method = access_log.info
26 elif status < 500:
27 log_method = access_log.warning
28 else:
29 log_method = access_log.error
30
31 request_time = 1000.0 * handler.request.request_time()
32 ns = dict(
33 status=status,
34 method=request.method,
35 ip=request.remote_ip,
36 uri=request.uri,
37 request_time=request_time,
38 )
39 msg = "{status} {method} {uri} ({ip}) {request_time:.2f}ms"
40 if status >= 300:
41 # log referers on redirects
42 ns['referer'] = request.headers.get('Referer', 'None')
43 msg = msg + ' referer={referer}'
44 if status >= 400:
45 # log user agent for failed requests
46 ns['agent'] = request.headers.get('User-Agent', 'Unknown')
47 msg = msg + ' user-agent={agent}'
48 if status >= 500 and status != 502:
49 # log all headers if it caused an error
50 log_method(json.dumps(request.headers, indent=2))
51 log_method(msg.format(**ns))
52
@@ -210,7 +210,7 b' class IPythonConsoleApp(ConnectionFileMixin):'
210 210 except Exception:
211 211 self.log.critical("Could not find existing kernel connection file %s", self.existing)
212 212 self.exit(1)
213 self.log.info("Connecting to existing kernel: %s" % cf)
213 self.log.debug("Connecting to existing kernel: %s" % cf)
214 214 self.connection_file = cf
215 215 else:
216 216 # not existing, check if we are going to write the file
@@ -303,8 +303,8 b' class IPythonConsoleApp(ConnectionFileMixin):'
303 303 base,ext = os.path.splitext(cf)
304 304 base = os.path.basename(base)
305 305 self.connection_file = os.path.basename(base)+'-ssh'+ext
306 self.log.critical("To connect another client via this tunnel, use:")
307 self.log.critical("--existing %s" % self.connection_file)
306 self.log.info("To connect another client via this tunnel, use:")
307 self.log.info("--existing %s" % self.connection_file)
308 308
309 309 def _new_connection_file(self):
310 310 cf = ''
@@ -64,7 +64,7 b' from tornado import web'
64 64 # Our own libraries
65 65 from IPython.html import DEFAULT_STATIC_FILES_PATH
66 66 from .base.handlers import Template404
67
67 from .log import log_request
68 68 from .services.kernels.kernelmanager import MappingKernelManager
69 69 from .services.notebooks.nbmanager import NotebookManager
70 70 from .services.notebooks.filenbmanager import FileNotebookManager
@@ -158,6 +158,7 b' class NotebookWebApplication(web.Application):'
158 158 template_path = settings_overrides.get("template_path", os.path.join(os.path.dirname(__file__), "templates"))
159 159 settings = dict(
160 160 # basics
161 log_function=log_request,
161 162 base_project_url=base_project_url,
162 163 base_kernel_url=ipython_app.base_kernel_url,
163 164 template_path=template_path,
@@ -519,7 +519,7 b' class ConnectionFileMixin(Configurable):'
519 519 """Create a zmq Socket and connect it to the kernel."""
520 520 url = self._make_url(channel)
521 521 socket_type = channel_socket_types[channel]
522 self.log.info("Connecting to: %s" % url)
522 self.log.debug("Connecting to: %s" % url)
523 523 sock = self.context.socket(socket_type)
524 524 if identity:
525 525 sock.identity = identity
General Comments 0
You need to be logged in to leave comments. Login now