Class Loggers

Synopsis

#include <src/easylogging++.h>

class Loggers : base::StaticClass

Description

Static helpers to deal with loggers and their configurations.

Mentioned in

Inheritance

Ancestors: StaticClass

Classes

ScopedAddFlagAdds flag and removes it when scope goes out.
ScopedRemoveFlagRemoves flag and add it when scope goes out.

Methods

addFlagAdds logging flag used internally.
clearVModulesClears vmodules.
configureFromArgConfigures loggers using command line arg. Ensure you have already set command line args,.
configureFromGlobalSets configurations from global configuration file.
defaultConfigurationsReturns current default.
defaultTypedConfigurationsDefault typed configuration based on existing defaultConf.
flushAllFlushes all loggers for all levels - Be careful if you dont know how many loggers are registered.
getLoggerGets existing or registers new logger.
hasFlagDetermines whether or not certain flag is active.
hasLoggerWhether or not logger with id is registered.
installLoggerRegistrationCallbackInstalls logger registration callback, this callback is triggered when new logger is registered.
loggerRegistrationCallback
logStreamsReferenceReturns log stream reference pointer if needed by user.
populateAllLoggerIdsPopulates all logger IDs in current repository.
reconfigureAllLoggers overloadReconfigures all the existing loggers with new configurations.
reconfigureAllLoggers overloadReconfigures single configuration for all the loggers.
reconfigureAllLoggers overloadReconfigures single configuration for all the loggers for specified level.
reconfigureLogger overloadReconfigures specified logger with new configurations.
reconfigureLogger overloadReconfigures logger with new configurations after looking it up using identity.
reconfigureLogger overloadReconfigures logger's single configuration.
removeFlagRemoves logging flag used internally.
setDefaultConfigurationsSets default configurations. This configuration is used for future (and conditionally for existing) loggers.
setDefaultLogBuilderChanges default log builder for future loggers.
setLoggingLevelSets hierarchy for logging. Needs to enable logging flag (HierarchicalLogging)
setVerboseLevelSets verbose level on the fly.
setVModulesSets vmodules as specified (on the fly)
uninstallLoggerRegistrationCallbackUninstalls log dispatch callback.
unregisterLoggerUnregisters logger - use it only when you know what you are doing, you may unregister loggers initialized / used by third-party libs.
verboseLevelGets current verbose level.

Source

Lines 3787-3897 in src/easylogging++.h.

class Loggers : base::StaticClass {
 public:
  /// @brief Gets existing or registers new logger
  static Logger* getLogger(const std::string& identity, bool registerIfNotAvailable = true);
  /// @brief Changes default log builder for future loggers
  static void setDefaultLogBuilder(el::LogBuilderPtr& logBuilderPtr);
  /// @brief Installs logger registration callback, this callback is triggered when new logger is registered
  template <typename T>
  static inline bool installLoggerRegistrationCallback(const std::string& id) {
    return ELPP->registeredLoggers()->installLoggerRegistrationCallback<T>(id);
  }
  /// @brief Uninstalls log dispatch callback
  template <typename T>
  static inline void uninstallLoggerRegistrationCallback(const std::string& id) {
    ELPP->registeredLoggers()->uninstallLoggerRegistrationCallback<T>(id);
  }
  template <typename T>
  static inline T* loggerRegistrationCallback(const std::string& id) {
    return ELPP->registeredLoggers()->loggerRegistrationCallback<T>(id);
  }
  /// @brief Unregisters logger - use it only when you know what you are doing, you may unregister
  ///        loggers initialized / used by third-party libs.
  static bool unregisterLogger(const std::string& identity);
  /// @brief Whether or not logger with id is registered
  static bool hasLogger(const std::string& identity);
  /// @brief Reconfigures specified logger with new configurations
  static Logger* reconfigureLogger(Logger* logger, const Configurations& configurations);
  /// @brief Reconfigures logger with new configurations after looking it up using identity
  static Logger* reconfigureLogger(const std::string& identity, const Configurations& configurations);
  /// @brief Reconfigures logger's single configuration
  static Logger* reconfigureLogger(const std::string& identity, ConfigurationType configurationType,
                                   const std::string& value);
  /// @brief Reconfigures all the existing loggers with new configurations
  static void reconfigureAllLoggers(const Configurations& configurations);
  /// @brief Reconfigures single configuration for all the loggers
  static inline void reconfigureAllLoggers(ConfigurationType configurationType, const std::string& value) {
    reconfigureAllLoggers(Level::Global, configurationType, value);
  }
  /// @brief Reconfigures single configuration for all the loggers for specified level
  static void reconfigureAllLoggers(Level level, ConfigurationType configurationType,
                                    const std::string& value);
  /// @brief Sets default configurations. This configuration is used for future (and conditionally for existing) loggers
  static void setDefaultConfigurations(const Configurations& configurations,
                                       bool reconfigureExistingLoggers = false);
  /// @brief Returns current default
  static const Configurations* defaultConfigurations(void);
  /// @brief Returns log stream reference pointer if needed by user
  static const base::LogStreamsReferenceMapPtr logStreamsReference(void);
  /// @brief Default typed configuration based on existing defaultConf
  static base::TypedConfigurations defaultTypedConfigurations(void);
  /// @brief Populates all logger IDs in current repository.
  /// @param [out] targetList List of fill up.
  static std::vector<std::string>* populateAllLoggerIds(std::vector<std::string>* targetList);
  /// @brief Sets configurations from global configuration file.
  static void configureFromGlobal(const char* globalConfigurationFilePath);
  /// @brief Configures loggers using command line arg. Ensure you have already set command line args,
  /// @return False if invalid argument or argument with no value provided, true if attempted to configure logger.
  ///         If true is returned that does not mean it has been configured successfully, it only means that it
  ///         has attempted to configure logger using configuration file provided in argument
  static bool configureFromArg(const char* argKey);
  /// @brief Flushes all loggers for all levels - Be careful if you dont know how many loggers are registered
  static void flushAll(void);
  /// @brief Adds logging flag used internally.
  static inline void addFlag(LoggingFlag flag) {
    ELPP->addFlag(flag);
  }
  /// @brief Removes logging flag used internally.
  static inline void removeFlag(LoggingFlag flag) {
    ELPP->removeFlag(flag);
  }
  /// @brief Determines whether or not certain flag is active
  static inline bool hasFlag(LoggingFlag flag) {
    return ELPP->hasFlag(flag);
  }
  /// @brief Adds flag and removes it when scope goes out
  class ScopedAddFlag {
   public:
    ScopedAddFlag(LoggingFlag flag) : m_flag(flag) {
      Loggers::addFlag(m_flag);
    }
    ~ScopedAddFlag(void) {
      Loggers::removeFlag(m_flag);
    }
   private:
    LoggingFlag m_flag;
  };
  /// @brief Removes flag and add it when scope goes out
  class ScopedRemoveFlag {
   public:
    ScopedRemoveFlag(LoggingFlag flag) : m_flag(flag) {
      Loggers::removeFlag(m_flag);
    }
    ~ScopedRemoveFlag(void) {
      Loggers::addFlag(m_flag);
    }
   private:
    LoggingFlag m_flag;
  };
  /// @brief Sets hierarchy for logging. Needs to enable logging flag (HierarchicalLogging)
  static void setLoggingLevel(Level level) {
    ELPP->setLoggingLevel(level);
  }
  /// @brief Sets verbose level on the fly
  static void setVerboseLevel(base::type::VerboseLevel level);
  /// @brief Gets current verbose level
  static base::type::VerboseLevel verboseLevel(void);
  /// @brief Sets vmodules as specified (on the fly)
  static void setVModules(const char* modules);
  /// @brief Clears vmodules
  static void clearVModules(void);
};





Add Discussion

Log in to comment