class Logger(object): def __init__(self, name): self._log = TMsgLogger() self._log.SetSource(name) self._log.SetMinLevel(INFO) self._levelLock = False def setLevel(self, level, lock=False): if (self._log.GetLevelLock()): self.warning("Cannot set log level again, current setting is %s" % self._log.GetMinLevelStr()) return self._log.SetMinLevel(_checkLevel(level), lock) self.always("Log level set to %s " % getLevelName(level)) if (lock): self.always("This log level is the final setting") def verbose(self, msg): self._log.writeLogMessage(VERBOSE, msg) def debug(self, msg): self._log.writeLogMessage(DEBUG, msg) def info(self, msg): self._log.writeLogMessage(INFO, msg) def warning(self, msg): self._log.writeLogMessage(WARNING, msg) def error(self, msg): self._log.writeLogMessage(ERROR, msg) def fatal(self, msg): self._log.writeLogMessage(FATAL, msg) def always(self, msg): self._log.writeLogMessage(ALWAYS, msg)
class Logger(object): def __init__(self, name): """ Initialise a logger @param name The name of the logger to initialise """ self._log = TMsgLogger() self._log.SetSource(name) self._log.SetMinLevel(INFO) self._levelLock = False def setLevel(self, level, lock=False): """ Set the level for the logger @param level The level to set @param lock Boolean that determines whether this method may be called again """ if (self._log.GetLevelLock()): self.warning("Cannot set log level again, current setting is %s" % self._log.GetMinLevelStr()) return self._log.SetMinLevel(_checkLevel(level), lock) self.always("Log level set to %s " % getLevelName(level)) if (lock): self.always("This log level is the final setting") def verbose(self, msg): """ Write out a message at the verbose level @param msg The message to write out """ self._log.writeLogMessage(VERBOSE, msg) def debug(self, msg): """ Write out a message at the debug level @param msg The message to write out """ self._log.writeLogMessage(DEBUG, msg) def info(self, msg): """ Write out a message at the info level @param msg The message to write out """ self._log.writeLogMessage(INFO, msg) def warning(self, msg): """ Write out a message at the warning level @param msg The message to write out """ self._log.writeLogMessage(WARNING, msg) def error(self, msg): """ Write out a message at the error level @param msg The message to write out """ self._log.writeLogMessage(ERROR, msg) def fatal(self, msg): """ Write out a message at the fatal level @param msg The message to write out """ self._log.writeLogMessage(FATAL, msg) def always(self, msg): """ Write out a message at the always level @param msg The message to write out """ self._log.writeLogMessage(ALWAYS, msg)