Belle II Software  release-05-02-19
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 7 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 12 of file logfilter.py.

12  def __init__(self, out, replacements):
13  """Setup the forwarding and replacements
14 
15  Parameters:
16  out (file object): Where to forward the output too
17  replacements (dict(str, str)): Dictionary of strings and their replacements
18  """
19 
20  self._out = out
21 
22  self._replacements = replacements
23 
24  self._regex = re.compile("|".join(re.escape(e) for e in replacements))
25 

Member Function Documentation

◆ __getattr__()

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

Definition at line 31 of file logfilter.py.

◆ write()

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

Definition at line 26 of file logfilter.py.


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