Package rrlog :: Package contrib :: Module catarch_file
[hide private]
[frames] | no frames]

Source Code for Module rrlog.contrib.catarch_file

 1  #Copyright (c) 2007 
 2  #        Ruben Reifenberg, Germany, 07381. 
 3  #    All rights reserved. 
 4  # 
 5  #Redistribution and use in source and binary forms, with or without 
 6  #modification, are permitted provided that the following conditions 
 7  #are met: 
 8  #1. Redistributions of source code must retain the above copyright 
 9  #   notice, this list of conditions and the following disclaimer as 
10  #   the first lines of this file unmodified. 
11  #2. Redistributions in binary form must reproduce the above copyright 
12  #   notice, this list of conditions and the following disclaimer in the 
13  #   documentation and/or other materials provided with the distribution. 
14  # 
15  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 
16  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
17  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
18  # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 
19  # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
20  # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
21  # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
22  # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
23  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
24  # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
25  # SUCH DAMAGE. 
26   
27  """ 
28  @summary: archives selected messages into own files. 
29  "Selected messages" are messages with certain defined "cat" values. 
30  @author: Ruben Reifenberg 
31  """ 
32   
33  from rrlog.server.filewriter import createRotatingServer,LOGWRITER_CLASS 
34  from rrlog.contrib.catarch import CatArchiver 
35   
36   
37   
38 -def createCatArchiver( 39 filePathPattern, 40 minArchCount=10, 41 minClientArchCount=1, 42 cats=None, 43 problemCats=None, 44 maxCount=10000, 45 format_line=None, 46 observers=None, 47 filters=None, 48 ):
49 """ 50 See L{rrlog.contrib.catarch.CatArchiver.__init__} for specification of the parameters. 51 @param format_line: See L{rrlog.server.textwriter.TextlineLogWriter.__init__} 52 @param problemCats: DEPRECATED, use cats instead. 53 """ 54 if problemCats is not None: 55 assert cats is None, "use cats parameter only. problemCats (deprecated) cannot be used same time." 56 cats = problemCats 57 return CatArchiver( 58 server = createRotatingServer( 59 filePathPattern=filePathPattern, 60 rotateCount=1, 61 rotateLineMin=None, 62 logwriterFactory=lambda *args,**kwargs:_FileLogWriter(format_line=format_line,*args,**kwargs), # provides additional columns 63 observers=observers, 64 filters=filters, 65 ), 66 minArchCount=minArchCount, 67 minClientArchCount=minClientArchCount, 68 maxCount=maxCount, 69 cats=cats, 70 )
71 72
73 -class _FileLogWriter(LOGWRITER_CLASS):
74 - def _format_line(self, job):
75 """ 76 Default formatting method. 77 @rtype: str 78 @return: single log line 79 """ 80 lineCount = "%s:"%(self._lineCount) 81 return "Trigger#%s:%s[%s]%s/ %s *%s(%s) %s\n"%( 82 job.trigger_id, 83 lineCount, 84 job.msgid, 85 job.ts, 86 job.msg, 87 job.cfn(), 88 job.cln(), 89 job.pathStr(1), 90 )
91