Belle II Software  release-06-00-14
LogReplacementFilter Class Reference

Public Member Functions

def __init__ (self, out, replacements)
 
def write (self, data)
 
def __getattr__ (self, name)
 

Private Attributes

 _out
 where to forward output
 
 _replacements
 what to replace
 
 _regex
 build a regular expression from dictionary keys
 

Detailed Description

Simple class to intercept anything written to python stdout and replace
a given set of strings with placehholders to improve reproducibility.

Definition at line 14 of file logfilter.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  out,
  replacements 
)
Setup the forwarding and replacements

Parameters:
    out (file object): Where to forward the output too
    replacements (dict(str, str)): Dictionary of strings and their replacements

Definition at line 19 of file logfilter.py.

19  def __init__(self, out, replacements):
20  """Setup the forwarding and replacements
21 
22  Parameters:
23  out (file object): Where to forward the output too
24  replacements (dict(str, str)): Dictionary of strings and their replacements
25  """
26 
27  self._out = out
28 
29  self._replacements = replacements
30 
31  self._regex = re.compile("|".join(re.escape(e) for e in replacements))
32 

Member Function Documentation

◆ __getattr__()

def __getattr__ (   self,
  name 
)
Forward all other methods from the out stream

Definition at line 38 of file logfilter.py.

◆ write()

def write (   self,
  data 
)
Check all messages for strings to replace

Definition at line 33 of file logfilter.py.


The documentation for this class was generated from the following file: