logging: implement FATAL and DFATAL log levels
[folly.git] / folly / experimental / logging / LogCategory.h
index a94471339f626da8320a24e7d71be60ad0c8d2cd..ce97c918bbe75660098ddfb970efcc6e9aeeea1d 100644 (file)
@@ -129,19 +129,6 @@ class LogCategory {
    */
   void setLevel(LogLevel level, bool inherit = true);
 
-  /**
-   * Process a log message.
-   *
-   * This method generally should be invoked through the Logger APIs,
-   * rather than calling this directly.
-   *
-   * This method assumes that log level admittance checks have already been
-   * performed.  This method unconditionally passes the message to the
-   * LogHandlers attached to this LogCategory, without any additional log level
-   * checks (apart from the ones done in the LogHandlers).
-   */
-  void processMessage(const LogMessage& message) const;
-
   /**
    * Get the LoggerDB that this LogCategory belongs to.
    *
@@ -163,6 +150,24 @@ class LogCategory {
    */
   void clearHandlers();
 
+  /**
+   * Get the list of LogHandlers attached to this category.
+   */
+  std::vector<std::shared_ptr<LogHandler>> getHandlers() const;
+
+  /* Internal methods for use by other parts of the logging library code */
+
+  /**
+   * Admit a message into the LogCategory hierarchy to be logged.
+   *
+   * The caller is responsible for having already performed log level
+   * admittance checks.
+   *
+   * This method generally should be invoked only through the logging macros,
+   * rather than calling this directly.
+   */
+  void admitMessage(const LogMessage& message) const;
+
   /**
    * Note: setLevelLocked() may only be called while holding the main
    * LoggerDB lock.
@@ -171,6 +176,18 @@ class LogCategory {
    */
   void setLevelLocked(LogLevel level, bool inherit);
 
+  /**
+   * Register a std::atomic<LogLevel> value used by XLOG*() macros to check the
+   * effective level for this category.
+   *
+   * The LogCategory will keep this value updated whenever its effective log
+   * level changes.
+   *
+   * This function should only be invoked by LoggerDB, and the LoggerDB lock
+   * must be held when calling it.
+   */
+  void registerXlogLevel(std::atomic<LogLevel>* levelPtr);
+
  private:
   enum : uint32_t { FLAG_INHERIT = 0x80000000 };
 
@@ -178,6 +195,7 @@ class LogCategory {
   LogCategory(LogCategory const&) = delete;
   LogCategory& operator=(LogCategory const&) = delete;
 
+  void processMessage(const LogMessage& message) const;
   void updateEffectiveLevel(LogLevel newEffectiveLevel);
   void parentLevelUpdated(LogLevel parentEffectiveLevel);
 
@@ -228,5 +246,14 @@ class LogCategory {
    */
   LogCategory* firstChild_{nullptr};
   LogCategory* nextSibling_{nullptr};
+
+  /**
+   * A list of LogLevel values used by XLOG*() statements for this LogCategory.
+   * The XLOG*() statements will check these values.  We ensure they are kept
+   * up-to-date each time the effective log level changes for this category.
+   *
+   * This list may only be accessed while holding the main LoggerDB lock.
+   */
+  std::vector<std::atomic<LogLevel>*> xlogLevels_;
 };
 }