Skip to content

Commit

Permalink
added LogLineFilter, which supports filtering on namespace, operation…
Browse files Browse the repository at this point in the history
…, thread.
  • Loading branch information
Thomas Rueckstiess committed May 2, 2013
1 parent c474066 commit 9c0b25c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions mlogfilter/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,45 @@ def accept(self, logline):
return False



class LogLineFilter(BaseFilter):
"""
"""
filterArgs = [
('--namespace', {'action':'store', 'metavar':'NS', 'help':'only output log lines matching operations on NS.'}),
('--operation', {'action':'store', 'metavar':'OP', 'help':'only output log lines matching operations of type OP.'}),
('--thread', {'action':'store', 'help':'only output log lines of thread THREAD.'})
]

def __init__(self, commandLineArgs):
BaseFilter.__init__(self, commandLineArgs)

self.namespace = None
self.operation = None
self.thread = None

if 'namespace' in self.commandLineArgs and self.commandLineArgs['namespace']:
self.namespace = self.commandLineArgs['namespace']
self.active = True
if 'operation' in self.commandLineArgs and self.commandLineArgs['operation']:
self.operation = self.commandLineArgs['operation']
self.active = True
if 'thread' in self.commandLineArgs and self.commandLineArgs['thread']:
self.thread = self.commandLineArgs['thread']
self.active = True

def accept(self, logline):
if self.namespace and logline.namespace == self.namespace:
return True
if self.operation and logline.operation == self.operation:
return True
if self.thread and logline.thread == self.thread:
return True

return False



class SlowFilter(BaseFilter):
""" accepts only lines that have a duration that is longer than the specified
parameter in ms (default 1000).
Expand Down
1 change: 1 addition & 0 deletions mlogfilter/mlogfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def parse(self):
mlogfilter = MongoLogFilter()

# add filters
mlogfilter.addFilter(LogLineFilter)
mlogfilter.addFilter(SlowFilter)
mlogfilter.addFilter(WordFilter)
mlogfilter.addFilter(TableScanFilter)
Expand Down

0 comments on commit 9c0b25c

Please sign in to comment.