Fix/clean up setLogLevel (#1016)
Sometimes we got no output with python 3 on ubuntu 20 This simplifies setLogLevel slightly and should work on python 2 and python 3.
This commit is contained in:
+7
-17
@@ -4,6 +4,7 @@ import logging
|
|||||||
from logging import Logger
|
from logging import Logger
|
||||||
import types
|
import types
|
||||||
|
|
||||||
|
|
||||||
# Create a new loglevel, 'CLI info', which enables a Mininet user to see only
|
# Create a new loglevel, 'CLI info', which enables a Mininet user to see only
|
||||||
# the output of the commands they execute, plus any errors or warnings. This
|
# the output of the commands they execute, plus any errors or warnings. This
|
||||||
# level is in between info and warning. CLI info-level commands should not be
|
# level is in between info and warning. CLI info-level commands should not be
|
||||||
@@ -105,30 +106,21 @@ class MininetLogger( Logger, object ):
|
|||||||
formatter = logging.Formatter( LOGMSGFORMAT )
|
formatter = logging.Formatter( LOGMSGFORMAT )
|
||||||
# add formatter to ch
|
# add formatter to ch
|
||||||
ch.setFormatter( formatter )
|
ch.setFormatter( formatter )
|
||||||
# add ch to lg
|
# add ch to lg and initialize log level
|
||||||
self.addHandler( ch )
|
self.addHandler( ch )
|
||||||
|
self.ch = ch
|
||||||
self.setLogLevel()
|
self.setLogLevel()
|
||||||
|
|
||||||
def setLogLevel( self, levelname=None ):
|
def setLogLevel( self, levelname=None ):
|
||||||
"""Setup loglevel.
|
"""Setup loglevel.
|
||||||
Convenience function to support lowercase names.
|
Convenience function to support lowercase names.
|
||||||
levelName: level name from LEVELS"""
|
levelName: level name from LEVELS"""
|
||||||
level = LOGLEVELDEFAULT
|
if levelname and levelname not in LEVELS:
|
||||||
if levelname is not None:
|
raise Exception( 'setLogLevel: unknown levelname %s' % levelname )
|
||||||
if levelname not in LEVELS:
|
level = LEVELS.get( levelname, LOGLEVELDEFAULT )
|
||||||
raise Exception( 'unknown levelname seen in setLogLevel' )
|
|
||||||
else:
|
|
||||||
level = LEVELS.get( levelname, level )
|
|
||||||
|
|
||||||
self.setLevel( level )
|
self.setLevel( level )
|
||||||
self.handlers[ 0 ].setLevel( level )
|
self.ch.setLevel( level )
|
||||||
|
|
||||||
# pylint: disable=method-hidden
|
|
||||||
# "An attribute inherited from mininet.log hide this method" (sic)
|
|
||||||
# Not sure why this is occurring - this function definitely gets called.
|
|
||||||
|
|
||||||
# See /usr/lib/python2.5/logging/__init__.py; modified from warning()
|
|
||||||
def output( self, msg, *args, **kwargs ):
|
def output( self, msg, *args, **kwargs ):
|
||||||
"""Log 'msg % args' with severity 'OUTPUT'.
|
"""Log 'msg % args' with severity 'OUTPUT'.
|
||||||
|
|
||||||
@@ -142,8 +134,6 @@ class MininetLogger( Logger, object ):
|
|||||||
if self.isEnabledFor( OUTPUT ):
|
if self.isEnabledFor( OUTPUT ):
|
||||||
self._log( OUTPUT, msg, args, kwargs )
|
self._log( OUTPUT, msg, args, kwargs )
|
||||||
|
|
||||||
# pylint: enable=method-hidden
|
|
||||||
|
|
||||||
|
|
||||||
lg = MininetLogger()
|
lg = MininetLogger()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user