Revision ddfbfc73 mininet/log.py

View differences:

mininet/log.py
108 108
    def setLogLevel( self, levelname=None ):
109 109
        """Setup loglevel.
110 110
           Convenience function to support lowercase names.
111

  
112 111
           levelName: level name from LEVELS"""
113 112
        level = LOGLEVELDEFAULT
114 113
        if levelname != None:
115 114
            if levelname not in LEVELS:
116
                raise Exception( 'unknown loglevel seen in set_loglevel' )
115
                raise Exception( 'unknown levelname seen in setLogLevel' )
117 116
            else:
118 117
                level = LEVELS.get( levelname, level )
119 118

  
......
122 121

  
123 122

  
124 123
lg = MininetLogger()
125
info, warn, error, debug = lg.info, lg.warn, lg.error, lg.debug
124

  
125
# Make things a bit more convenient by adding aliases
126
# (info, warn, error, debug) and allowing info( 'this', 'is', 'OK' )
127
# In the future we may wish to make things more efficient by only
128
# doing the join (and calling the function) unless the logging level
129
# is high enough.
130

  
131
def makeListCompatible( fn ):
132
    """Return a new function allowing fn( 'a 1 b' ) to be called as
133
       newfn( 'a', 1, 'b' )"""
134

  
135
    def newfn( *args ):
136
        "Generated function."
137
        if len( args ) == 1:
138
            return fn( *args )
139
        args = ' '.join( [ str( arg ) for arg in args ] )
140
        return fn( args )
141

  
142
    # Fix newfn's name and docstring
143
    setattr( newfn, '__name__', fn.__name__ )
144
    setattr( newfn, '__doc__', fn.__doc__ )
145
    return newfn
146

  
147
info, warn, error, debug = lg.info, lg.warn, lg.error, lg.debug = [
148
    makeListCompatible( f ) for f in lg.info, lg.warn, lg.error, lg.debug ]

Also available in: Unified diff