diff --git a/mininet/log.py b/mininet/log.py index bb615924251e76c12bfd191f89c23785f39bf5f8..a8e53a84263366e08276d471def26017bc674467 100644 --- a/mininet/log.py +++ b/mininet/log.py @@ -108,12 +108,11 @@ def __init__( self ): def setLogLevel( self, levelname=None ): """Setup loglevel. Convenience function to support lowercase names. - levelName: level name from LEVELS""" level = LOGLEVELDEFAULT if levelname != None: if levelname not in LEVELS: - raise Exception( 'unknown loglevel seen in set_loglevel' ) + raise Exception( 'unknown levelname seen in setLogLevel' ) else: level = LEVELS.get( levelname, level ) @@ -122,4 +121,28 @@ def setLogLevel( self, levelname=None ): lg = MininetLogger() -info, warn, error, debug = lg.info, lg.warn, lg.error, lg.debug + +# Make things a bit more convenient by adding aliases +# (info, warn, error, debug) and allowing info( 'this', 'is', 'OK' ) +# In the future we may wish to make things more efficient by only +# doing the join (and calling the function) unless the logging level +# is high enough. + +def makeListCompatible( fn ): + """Return a new function allowing fn( 'a 1 b' ) to be called as + newfn( 'a', 1, 'b' )""" + + def newfn( *args ): + "Generated function." + if len( args ) == 1: + return fn( *args ) + args = ' '.join( [ str( arg ) for arg in args ] ) + return fn( args ) + + # Fix newfn's name and docstring + setattr( newfn, '__name__', fn.__name__ ) + setattr( newfn, '__doc__', fn.__doc__ ) + return newfn + +info, warn, error, debug = lg.info, lg.warn, lg.error, lg.debug = [ + makeListCompatible( f ) for f in lg.info, lg.warn, lg.error, lg.debug ]