Browse Source

[trac901] Some cleanups and documentation

Michal 'vorner' Vaner 14 years ago
parent
commit
7c40e60eea
4 changed files with 19 additions and 83 deletions
  1. 8 4
      src/lib/log/logger.h
  2. 0 23
      src/lib/log/logger_impl.cc
  3. 6 56
      src/lib/log/logger_impl.h
  4. 5 0
      src/lib/log/macros.h

+ 8 - 4
src/lib/log/logger.h

@@ -49,9 +49,6 @@ class LoggerImpl;   // Forward declaration of the implementation class
 class Logger {
 public:
 
-    typedef isc::log::Formatter<Logger> Formatter;
-    void output(const char* sevText, const std::string& message);
-
     /// \brief Constructor
     ///
     /// Creates/attaches to a logger of a specific name.
@@ -87,10 +84,11 @@ public:
         loggerptr_(NULL), name_(name), infunc_(infunc)
     {}
 
-
     /// \brief Destructor
     virtual ~Logger();
 
+    /// \brief The formatter used to replace placeholders
+    typedef isc::log::Formatter<Logger> Formatter;
 
     /// \brief Get Name of Logger
     ///
@@ -204,6 +202,12 @@ protected:
     static void reset();
 
 private:
+    friend class isc::log::Formatter<Logger>;
+    /// \brief Raw output function
+    ///
+    /// This is used by the formatter to output formatted output.
+    void output(const char* sevText, const std::string& message);
+
     /// \brief Copy Constructor
     ///
     /// Disabled (marked private) as it makes no sense to copy the logger -

+ 0 - 23
src/lib/log/logger_impl.cc

@@ -215,28 +215,5 @@ LoggerImpl::outputRaw(const char* sevText, const string& message) {
         message << endl;
 }
 
-void
-LoggerImpl::output(const char* sev_text, const MessageID& ident,
-    va_list ap)
-{
-    char message[512];      // Should be large enough for any message
-
-    // Obtain text of the message and substitute arguments.
-    const string format = MessageDictionary::globalDictionary().getText(ident);
-    vsnprintf(message, sizeof(message), format.c_str(), ap);
-
-    // Get the time in a struct tm format, and convert to text
-    time_t t_time;
-    time(&t_time);
-    struct tm* tm_time = localtime(&t_time);
-
-    char chr_time[32];
-    (void) strftime(chr_time, sizeof(chr_time), "%Y-%m-%d %H:%M:%S", tm_time);
-
-    // Now output.
-    std::cout << chr_time << " " << sev_text << " [" << getName() << "] " <<
-        ident << ", " << message << "\n";
-}
-
 } // namespace log
 } // namespace isc

+ 6 - 56
src/lib/log/logger_impl.h

@@ -167,66 +167,16 @@ public:
         }
     }
 
-
-    /// \brief Output General Message
-    ///
-    /// The message is formatted to include the date and time, the severity
-    /// and the logger generating the message.
+    /// \brief Raw output
     ///
-    /// \param sev_text Severity level as a text string
-    /// \param ident Message identification
-    /// \param ap Variable argument list holding message arguments
-    void output(const char* sev_text, const MessageID& ident,
-        va_list ap);
-
+    /// Writes the message with time into the log. Used by the Formatter
+    /// to produce output.
     void outputRaw(const char* sev_text, const std::string& message);
-    std::string* lookupMessage(const MessageID& id);
-
-    /// \brief Output Debug Message
-    ///
-    /// \param ident Message identification.
-    /// \param text Text to log
-    /// \param ap Variable argument list holding message arguments
-    void debug(const MessageID& ident, va_list ap) {
-        output("DEBUG", ident, ap);
-    }
-
 
-    /// \brief Output Informational Message
+    /// \brief Look up message text in dictionary
     ///
-    /// \param ident Message identification.
-    /// \param text Text to log
-    /// \param ap Variable argument list holding message arguments
-    void info(const MessageID& ident, va_list ap) {
-        output("INFO ", ident, ap);
-    }
-
-    /// \brief Output Warning Message
-    ///
-    /// \param ident Message identification.
-    /// \param text Text to log
-    /// \param ap Variable argument list holding message arguments
-    void warn(const MessageID& ident, va_list ap) {
-        output("WARN ", ident, ap);
-    }
-
-    /// \brief Output Error Message
-    ///
-    /// \param ident Message identification.
-    /// \param text Text to log
-    /// \param ap Variable argument list holding message arguments
-    void error(const MessageID& ident, va_list ap) {
-        output("ERROR", ident, ap);
-    }
-
-    /// \brief Output Fatal Message
-    ///
-    /// \param ident Message identification.
-    /// \param text Text to log
-    /// \param ap Variable argument list holding message arguments
-    void fatal(const MessageID& ident, va_list ap) {
-        output("FATAL", ident, ap);
-    }
+    /// This gets you the unformatted text of message for given ID.
+    std::string* lookupMessage(const MessageID& id);
 
     /// \brief Equality
     ///

+ 5 - 0
src/lib/log/macros.h

@@ -15,26 +15,31 @@
 #ifndef __LOG_MACROS_H
 #define __LOG_MACROS_H
 
+/// \brief Macro to conveniently test debug output and log it
 #define LOG_DEBUG(LOGGER, LEVEL, MESSAGE) \
     if (!(LOGGER).isDebugEnabled((LEVEL))) { \
     } else \
         (LOGGER).debug((LEVEL), (MESSAGE))
 
+/// \brief Macro to conveniently test info output and log it
 #define LOG_INFO(LOGGER, MESSAGE) \
     if (!(LOGGER).isInfoEnabled()) { \
     } else \
         (LOGGER).info((MESSAGE))
 
+/// \brief Macro to conveniently test warn output and log it
 #define LOG_WARN(LOGGER, MESSAGE) \
     if (!(LOGGER).isWarnEnabled()) { \
     } else \
         (LOGGER).warn((MESSAGE))
 
+/// \brief Macro to conveniently test error output and log it
 #define LOG_ERROR(LOGGER, MESSAGE) \
     if (!(LOGGER).isErrorEnabled()) { \
     } else \
         (LOGGER).error((MESSAGE))
 
+/// \brief Macro to conveniently test fatal output and log it
 #define LOG_FATAL(LOGGER, MESSAGE) \
     if (!(LOGGER).isFatalEnabled()) { \
     } else \