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