logger.h 1.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#ifndef AIRMAP_QT_LOGGER_H_
#define AIRMAP_QT_LOGGER_H_

#include <airmap/logger.h>

#include <QLoggingCategory>

#include <memory>

namespace airmap {
namespace qt {

/// Logger is an airmap::Logger implementation that uses to
/// Qt's logging facilities.
class Logger : public airmap::Logger {
 public:
  /// logging_category returns a QLoggingCategory instance
  /// that enables calling code to fine-tune logging behavior of a Logger instance.
  QLoggingCategory& logging_category();

  /// Logger initializes a new instance.
  Logger();
  /// ~Logger cleans up all resources held by a Logger instance.
  ~Logger();

  // From airmap::Logger
  void log(Severity severity, const char* message, const char* component) override;
  bool should_log(Severity severity, const char* message, const char* component) override;

 private:
  struct Private;
  std::unique_ptr<Private> d_;
};

/// DispatchingLogger is an airmap::Logger implementation that dispatches to Qt's main
/// event loop for logger invocation
class DispatchingLogger : public airmap::Logger {
 public:
  /// DispatchingLogger initializes a new instance with 'next'.
  DispatchingLogger(const std::shared_ptr<airmap::Logger>& next);
  /// ~DispatchingLogging cleans up all resources held a DispatchingLogger instance.
  ~DispatchingLogger();

  // From airmap::Logger
  void log(Severity severity, const char* message, const char* component) override;
  bool should_log(Severity severity, const char* message, const char* component) override;

 private:
  struct Private;
  std::unique_ptr<Private> d_;
};

}  // namespace qt
}  // namespace airmap

#endif  // AIRMAP_QT_LOGGER_H_