Class Storage

Synopsis

#include <src/easylogging++.h>

class Storage : base::NoCopy, public base::threading::ThreadSafe

Description

Easylogging++ management storage.

Inheritance

Ancestors: ThreadSafe, NoCopy

Methods

Storage overloadStorage.
~Storage
addFlag
asyncLogQueue
commandLineArgs
customFormatSpecifiers
customFormatSpecifiersLock
flags
getThreadName
hasCustomFormatSpecifier
hasFlag
hitCounters
installCustomFormatSpecifier
installLogDispatchCallback
installPerformanceTrackingCallback
logDispatchCallback
performanceTrackingCallback
preRollOutCallback
registeredLoggers
removeFlag
setFlags
setLoggingLevel
setPreRollOutCallback
setThreadNameSets thread name for current thread. Requires std::thread.
uninstallCustomFormatSpecifier
uninstallLogDispatchCallback
uninstallPerformanceTrackingCallback
unsetPreRollOutCallback
validateAfterNCounter
validateEveryNCounter
validateNTimesCounter
vRegistry

Source

Lines 2555-2727 in src/easylogging++.h.

class Storage : base::NoCopy, public base::threading::ThreadSafe {
 public:
#if ELPP_ASYNC_LOGGING
  Storage(const LogBuilderPtr& defaultLogBuilder, base::IWorker* asyncDispatchWorker);
#else
  explicit Storage(const LogBuilderPtr& defaultLogBuilder);
#endif  // ELPP_ASYNC_LOGGING

  virtual ~Storage(void);

  inline bool validateEveryNCounter(const char* filename, base::type::LineNumber lineNumber, std::size_t occasion) {
    return hitCounters()->validateEveryN(filename, lineNumber, occasion);
  }

  inline bool validateAfterNCounter(const char* filename, base::type::LineNumber lineNumber, std::size_t n) {
    return hitCounters()->validateAfterN(filename, lineNumber, n);
  }

  inline bool validateNTimesCounter(const char* filename, base::type::LineNumber lineNumber, std::size_t n) {
    return hitCounters()->validateNTimes(filename, lineNumber, n);
  }

  inline base::RegisteredHitCounters* hitCounters(void) const {
    return m_registeredHitCounters;
  }

  inline base::RegisteredLoggers* registeredLoggers(void) const {
    return m_registeredLoggers;
  }

  inline base::VRegistry* vRegistry(void) const {
    return m_vRegistry;
  }

#if ELPP_ASYNC_LOGGING
  inline base::AsyncLogQueue* asyncLogQueue(void) const {
    return m_asyncLogQueue;
  }
#endif  // ELPP_ASYNC_LOGGING

  inline const base::utils::CommandLineArgs* commandLineArgs(void) const {
    return &m_commandLineArgs;
  }

  inline void addFlag(LoggingFlag flag) {
    base::utils::addFlag(flag, &m_flags);
  }

  inline void removeFlag(LoggingFlag flag) {
    base::utils::removeFlag(flag, &m_flags);
  }

  inline bool hasFlag(LoggingFlag flag) const {
    return base::utils::hasFlag(flag, m_flags);
  }

  inline base::type::EnumType flags(void) const {
    return m_flags;
  }

  inline void setFlags(base::type::EnumType flags) {
    m_flags = flags;
  }

  inline void setPreRollOutCallback(const PreRollOutCallback& callback) {
    m_preRollOutCallback = callback;
  }

  inline void unsetPreRollOutCallback(void) {
    m_preRollOutCallback = base::defaultPreRollOutCallback;
  }

  inline PreRollOutCallback& preRollOutCallback(void) {
    return m_preRollOutCallback;
  }

  bool hasCustomFormatSpecifier(const char* formatSpecifier);
  void installCustomFormatSpecifier(const CustomFormatSpecifier& customFormatSpecifier);
  bool uninstallCustomFormatSpecifier(const char* formatSpecifier);

  const std::vector<CustomFormatSpecifier>* customFormatSpecifiers(void) const {
    return &m_customFormatSpecifiers;
  }

  base::threading::Mutex& customFormatSpecifiersLock() {
    return m_customFormatSpecifiersLock;
  }

  inline void setLoggingLevel(Level level) {
    m_loggingLevel = level;
  }

  template <typename T>
  inline bool installLogDispatchCallback(const std::string& id) {
    return base::utils::Utils::installCallback<T, base::type::LogDispatchCallbackPtr>(id, &m_logDispatchCallbacks);
  }

  template <typename T>
  inline void uninstallLogDispatchCallback(const std::string& id) {
    base::utils::Utils::uninstallCallback<T, base::type::LogDispatchCallbackPtr>(id, &m_logDispatchCallbacks);
  }
  template <typename T>
  inline T* logDispatchCallback(const std::string& id) {
    return base::utils::Utils::callback<T, base::type::LogDispatchCallbackPtr>(id, &m_logDispatchCallbacks);
  }

#if defined(ELPP_FEATURE_ALL) || defined(ELPP_FEATURE_PERFORMANCE_TRACKING)
  template <typename T>
  inline bool installPerformanceTrackingCallback(const std::string& id) {
    return base::utils::Utils::installCallback<T, base::type::PerformanceTrackingCallbackPtr>(id,
           &m_performanceTrackingCallbacks);
  }

  template <typename T>
  inline void uninstallPerformanceTrackingCallback(const std::string& id) {
    base::utils::Utils::uninstallCallback<T, base::type::PerformanceTrackingCallbackPtr>(id,
        &m_performanceTrackingCallbacks);
  }

  template <typename T>
  inline T* performanceTrackingCallback(const std::string& id) {
    return base::utils::Utils::callback<T, base::type::PerformanceTrackingCallbackPtr>(id, &m_performanceTrackingCallbacks);
  }
#endif // defined(ELPP_FEATURE_ALL) || defined(ELPP_FEATURE_PERFORMANCE_TRACKING)

  /// @brief Sets thread name for current thread. Requires std::thread
  inline void setThreadName(const std::string& name) {
    if (name.empty()) return;
    base::threading::ScopedLock scopedLock(m_threadNamesLock);
    m_threadNames[base::threading::getCurrentThreadId()] = name;
  }

  inline std::string getThreadName(const std::string& threadId) {
    base::threading::ScopedLock scopedLock(m_threadNamesLock);
    std::unordered_map<std::string, std::string>::const_iterator it = m_threadNames.find(threadId);
    if (it == m_threadNames.end()) {
      return threadId;
    }
    return it->second;
  }
 private:
  base::RegisteredHitCounters* m_registeredHitCounters;
  base::RegisteredLoggers* m_registeredLoggers;
  base::type::EnumType m_flags;
  base::VRegistry* m_vRegistry;
#if ELPP_ASYNC_LOGGING
  base::AsyncLogQueue* m_asyncLogQueue;
  base::IWorker* m_asyncDispatchWorker;
#endif  // ELPP_ASYNC_LOGGING
  base::utils::CommandLineArgs m_commandLineArgs;
  PreRollOutCallback m_preRollOutCallback;
  std::unordered_map<std::string, base::type::LogDispatchCallbackPtr> m_logDispatchCallbacks;
  std::unordered_map<std::string, base::type::PerformanceTrackingCallbackPtr> m_performanceTrackingCallbacks;
  std::unordered_map<std::string, std::string> m_threadNames;
  std::vector<CustomFormatSpecifier> m_customFormatSpecifiers;
  base::threading::Mutex m_customFormatSpecifiersLock;
  base::threading::Mutex m_threadNamesLock;
  Level m_loggingLevel;

  friend class el::Helpers;
  friend class el::base::DefaultLogDispatchCallback;
  friend class el::LogBuilder;
  friend class el::base::MessageBuilder;
  friend class el::base::Writer;
  friend class el::base::PerformanceTracker;
  friend class el::base::LogDispatcher;

  void setApplicationArguments(int argc, char** argv);

  inline void setApplicationArguments(int argc, const char** argv) {
    setApplicationArguments(argc, const_cast<char**>(argv));
  }
};





Add Discussion

Log in to comment