Class Logger

Synopsis

#include <src/easylogging++.h>

class Logger : public base::threading::ThreadSafe, public Loggable

Description

Represents a logger holding ID and configurations we need to write logs.

@detail This class does not write logs itself instead its used by writer to read configurations from.

Mentioned in

Inheritance

Ancestors: ThreadSafe, Loggable

Methods

Logger overloadLogger.
~Logger
configurations
configureConfigures the logger using specified configurations.
enabled
flush overloadFlushes logger to sync all log files for all levels.
id

Mentioned in

initUnflushedCount
isFlushNeeded
isValidId
log overload
log_ overloadLogging from Logger class. Why this is here? Because we have Storage and Writer class available.
logBuilder

Mentioned in

operator=
parentApplicationName
reconfigureReconfigures logger using existing configurations.
resolveLoggerFormatSpec
setLogBuilder
setParentApplicationName
stream
typedConfigurations

Mentioned in

verbose overload

Mentioned in

Source

Lines 2217-2348 in src/easylogging++.h.

class Logger : public base::threading::ThreadSafe, public Loggable {
 public:
  Logger(const std::string& id, base::LogStreamsReferenceMapPtr logStreamsReference);
  Logger(const std::string& id, const Configurations& configurations, base::LogStreamsReferenceMapPtr logStreamsReference);
  Logger(const Logger& logger);
  Logger& operator=(const Logger& logger);

  virtual ~Logger(void) {
    base::utils::safeDelete(m_typedConfigurations);
  }

  virtual inline void log(el::base::type::ostream_t& os) const {
    os << m_id.c_str();
  }

  /// @brief Configures the logger using specified configurations.
  void configure(const Configurations& configurations);

  /// @brief Reconfigures logger using existing configurations
  void reconfigure(void);

  inline const std::string& id(void) const {
    return m_id;
  }

  inline const std::string& parentApplicationName(void) const {
    return m_parentApplicationName;
  }

  inline void setParentApplicationName(const std::string& parentApplicationName) {
    m_parentApplicationName = parentApplicationName;
  }

  inline Configurations* configurations(void) {
    return &m_configurations;
  }

  inline base::TypedConfigurations* typedConfigurations(void) {
    return m_typedConfigurations;
  }

  static bool isValidId(const std::string& id);

  /// @brief Flushes logger to sync all log files for all levels
  void flush(void);

  void flush(Level level, base::type::fstream_t* fs);

  inline bool isFlushNeeded(Level level) {
    return ++m_unflushedCount.find(level)->second >= m_typedConfigurations->logFlushThreshold(level);
  }

  inline LogBuilder* logBuilder(void) const {
    return m_logBuilder.get();
  }

  inline void setLogBuilder(const LogBuilderPtr& logBuilder) {
    m_logBuilder = logBuilder;
  }

  inline bool enabled(Level level) const {
    return m_typedConfigurations->enabled(level);
  }

#if ELPP_VARIADIC_TEMPLATES_SUPPORTED
#  define LOGGER_LEVEL_WRITERS_SIGNATURES(FUNCTION_NAME)\
template <typename T, typename... Args>\
inline void FUNCTION_NAME(const char*, const T&, const Args&...);\
template <typename T>\
inline void FUNCTION_NAME(const T&);

  template <typename T, typename... Args>
  inline void verbose(int, const char*, const T&, const Args&...);

  template <typename T>
  inline void verbose(int, const T&);

  LOGGER_LEVEL_WRITERS_SIGNATURES(info)
  LOGGER_LEVEL_WRITERS_SIGNATURES(debug)
  LOGGER_LEVEL_WRITERS_SIGNATURES(warn)
  LOGGER_LEVEL_WRITERS_SIGNATURES(error)
  LOGGER_LEVEL_WRITERS_SIGNATURES(fatal)
  LOGGER_LEVEL_WRITERS_SIGNATURES(trace)
#  undef LOGGER_LEVEL_WRITERS_SIGNATURES
#endif // ELPP_VARIADIC_TEMPLATES_SUPPORTED
 private:
  std::string m_id;
  base::TypedConfigurations* m_typedConfigurations;
  base::type::stringstream_t m_stream;
  std::string m_parentApplicationName;
  bool m_isConfigured;
  Configurations m_configurations;
  std::unordered_map<Level, unsigned int> m_unflushedCount;
  base::LogStreamsReferenceMapPtr m_logStreamsReference = nullptr;
  LogBuilderPtr m_logBuilder;

  friend class el::LogMessage;
  friend class el::Loggers;
  friend class el::Helpers;
  friend class el::base::RegisteredLoggers;
  friend class el::base::DefaultLogDispatchCallback;
  friend class el::base::MessageBuilder;
  friend class el::base::Writer;
  friend class el::base::PErrorWriter;
  friend class el::base::Storage;
  friend class el::base::PerformanceTracker;
  friend class el::base::LogDispatcher;

  Logger(void);

#if ELPP_VARIADIC_TEMPLATES_SUPPORTED
  template <typename T, typename... Args>
  void log_(Level, int, const char*, const T&, const Args&...);

  template <typename T>
  inline void log_(Level, int, const T&);

  template <typename T, typename... Args>
  void log(Level, const char*, const T&, const Args&...);

  template <typename T>
  inline void log(Level, const T&);
#endif // ELPP_VARIADIC_TEMPLATES_SUPPORTED

  void initUnflushedCount(void);

  inline base::type::stringstream_t& stream(void) {
    return m_stream;
  }

  void resolveLoggerFormatSpec(void) const;
};





Add Discussion

Log in to comment