Commits

Lee McFadden committed ecbec08

Basic logging implemented.

  • Participants
  • Parent commits b3d5590

Comments (0)

Files changed (2)

src/lumberjack/middleware.py

         # Build the server instance.  New instance per request.
         server = Server(self.host)
         db = server.get_or_create_db(self.db)
+        Log.set_db(db)
 
         log = Log()
         log.log_start = datetime.utcnow()
-        for k, v in environ.values():
-            log_key = k.lower().replace(".", "__")
-            setattr(log, log_key, v)
 
         environ['lumberjack.log'] = log
 
         retval = self.app(environ, start_response)
 
+        from pprint import pformat
+        raise Exception(type(retval))
+
+        for k, v in environ.iteritems():
+            if not "." in k:
+                log_key = k.lower()
+                setattr(log, log_key, str(v))
+        log.reconstruct_url(environ)
+
         log.log_end = datetime.utcnow()
         log.save()
         return retval

src/lumberjack/schema.py

     path_info = StringProperty()
     query_string = StringProperty()
     content_type = StringProperty()
-    content_length = IntegerProperty()
+    content_length = StringProperty()
     server_name = StringProperty()
+    http_host = StringProperty()
     server_port = StringProperty()
     server_protocol = StringProperty()
     url = StringProperty()
 
-    def reconstruct_url(self):
-        url = "%s://" % self.wsgi__url_schemeenviron['wsgi.url_scheme']
+    def reconstruct_url(self, environ):
+        url = "%s://" % environ['wsgi.url_scheme']
 
         if hasattr(self, 'http_host'):
-            url += self.http_host
+            url += environ['HTTP_HOST']
         else:
-            url += self.server_name
+            url += environ['SERVER_NAME']
 
-            if self.wsgi__url_scheme == 'https':
-                if self.server_port != '443':
-                   url += ':%s' % self.server_port
+            if environ['wsgi.url_scheme'] == 'https':
+                if environ['SERVER_PORT'] != '443':
+                   url += ':%s' % environ['SERVER_PORT']
             else:
-                if self.server_port != '80':
-                   url += ':%s' % self.server_port
+                if environ['SERVER_PORT'] != '80':
+                   url += ':%s' % environ['SERVER_PORT']
 
-        if self.script_name:
-            url += quote(self.script_name)
-        if self.path_info:
-            url += quote(self.path_info)
-        if self.query_string:
-            url += '?' + self.query_string
+        if environ['SCRIPT_NAME']:
+            url += quote(environ['SCRIPT_NAME'])
+        if environ['PATH_INFO']:
+            url += quote(environ['PATH_INFO'])
+        if environ['QUERY_STRING']:
+            url += '?' + environ['QUERY_STRING']
 
-        return url
-
-    def save(self):
-        self.url = self.reconstruct_url()
-        super(Log, self).save()
+        self.url = url