Package flumotion :: Package component :: Package plugs :: Module request
[hide private]

Source Code for Module flumotion.component.plugs.request

 1  # -*- Mode: Python -*- 
 2  # vi:si:et:sw=4:sts=4:ts=4 
 3   
 4  # Flumotion - a streaming media server 
 5  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
 6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
 7  # All rights reserved. 
 8  # 
 9  # This file may be distributed and/or modified under the terms of 
10  # the GNU Lesser General Public License version 2.1 as published by 
11  # the Free Software Foundation. 
12  # This file is distributed without any warranty; without even the implied 
13  # warranty of merchantability or fitness for a particular purpose. 
14  # See "LICENSE.LGPL" in the source distribution for more information. 
15  # 
16  # Headers in this file shall remain intact. 
17   
18  import time 
19   
20  from flumotion.common import errors 
21  from flumotion.component.plugs import base 
22   
23  __version__ = "$Rev$" 
24   
25   
26 -class RequestLoggerPlug(base.ComponentPlug):
27 """ 28 Base class for logger implementations. Should be renamed to 29 StreamLogger later... 30 """ 31
32 - def event(self, type, args):
33 """ 34 Handle a log event. 35 36 This dispatches a particular event type such as 37 "http_session_completed" to a method "event_http_session_completed". 38 39 Returns a Deferred (which will fire once the event handling has been 40 completed), or None. 41 """ 42 handler = getattr(self, 'event_' + type, None) 43 if handler: 44 return handler(args)
45
46 - def rotate(self):
47 # do nothing by default 48 pass
49 50
51 -def _http_session_completed_to_apache_log(args):
52 # ident is something that should in theory come from identd but in 53 # practice is never there 54 ident = '-' 55 date = time.strftime('%d/%b/%Y:%H:%M:%S +0000', args['time']) 56 57 return ("%s %s %s [%s] \"%s %s %s\" %d %d %s \"%s\" %d\n" 58 % (args['ip'], ident, args['username'], date, 59 args['method'], args['uri'], args['clientproto'], 60 args['response'], args['bytes-sent'], args['referer'], 61 args['user-agent'], args['time-connected']))
62 63
64 -class RequestLoggerFilePlug(RequestLoggerPlug):
65 filename = None 66 file = None 67
68 - def start(self, component=None):
69 self.filename = self.args['properties']['logfile'] 70 try: 71 self.file = open(self.filename, 'a') 72 except IOError, data: 73 raise errors.PropertyError('could not open log file %s ' 74 'for writing (%s)' 75 % (self.filename, data[1]))
76
77 - def stop(self, component=None):
78 if self.file: 79 self.file.close() 80 self.file = None
81
82 - def event_http_session_completed(self, args):
85
86 - def rotate(self):
87 self.stop() 88 self.start()
89