Better logger initialization
@@ -232,13 +232,20 @@ def cnn_model(*args, **kwargs):
" after 2018-01-05. Switch to utils_keras.cnn_model.")
return cnn_model(*args, **kwargs)
-_logger = logging.getLogger("cleverhans")
-_logger.setLevel(logging.DEBUG)
+def create_logger(name):
+ """
+ Create a logger object with the given name.
+
+ If this is the first time that we call this method, then initialize the
+ formatter.
+ """
+ base = logging.getLogger("cleverhans")
+ if len(base.handlers) == 0:
ch = logging.StreamHandler()
-formatter = logging.Formatter('[%(levelname)s %(asctime)s %(name)s] %(message)s')
+ formatter = logging.Formatter('[%(levelname)s %(asctime)s %(name)s] ' +
+ '"%(message)s')
ch.setFormatter(formatter)
_logger.addHandler(ch)
-def create_logger(name):
_logger = logging.getLogger(name)
return _logger
