Commit in slic on MAIN
include/LogLevel.hh+661.3 -> 1.4
       /Logger.hh+501.3 -> 1.4
src/LogLevel.cc+141.3 -> 1.4
   /Logger.cc+821.3 -> 1.4
+212
4 modified files
Added basic logging classes.  (Work in progress.)

slic/include
LogLevel.hh 1.3 -> 1.4
diff -N LogLevel.hh
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ LogLevel.hh	13 Oct 2005 01:28:03 -0000	1.4
@@ -0,0 +1,66 @@
+// $Header: /cvs/lcd/slic/include/LogLevel.hh,v 1.4 2005/10/13 01:28:03 jeremy Exp $
+#ifndef slic_LogLevel_hh
+#define slic_LogLevel_hh 1
+
+// std
+#include <string>
+
+namespace slic
+{
+
+  /**
+   * @class LogLevel
+   * @brief An enum-like class for setting the log level of Logger objects.
+   */
+  class LogLevel
+  {
+
+  public:
+
+    enum ELogLevel {
+      eNone    = 0,
+      eFatal   = 1,
+      eError   = 2,
+      eWarn    = 3,
+      eOkay    = 4,
+      eDebug   = 5,
+      eVerbose = 6
+    };
+
+    static const LogLevel DEFAULT;
+    static const LogLevel NONE;
+    static const LogLevel FATAL;
+    static const LogLevel ERROR;
+    static const LogLevel WARN;
+    static const LogLevel DEBUG;
+    static const LogLevel OKAY;
+    static const LogLevel VERBOSE;
+
+  protected:
+    LogLevel(ELogLevel level = eNone,
+	     const std::string& name = "")
+      : m_level(level),
+	m_name(name)
+    {}
+
+  public:
+    virtual ~LogLevel()
+    {}
+
+    const std::string& toString() const
+    {
+      return m_name;
+    }
+
+    bool operator<=(LogLevel& right) const
+    {
+      return m_level <= right.m_level;
+    }
+
+  private:
+    ELogLevel m_level;
+    std::string m_name;
+  };
+}
+
+#endif

slic/include
Logger.hh 1.3 -> 1.4
diff -N Logger.hh
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Logger.hh	13 Oct 2005 01:28:04 -0000	1.4
@@ -0,0 +1,50 @@
+// $Header: /cvs/lcd/slic/include/Logger.hh,v 1.4 2005/10/13 01:28:04 jeremy Exp $
+#ifndef slic_Logger_hh
+#define slic_Logger_hh
+
+// slic
+#include "LogLevel.hh"
+
+// std
+#include <iostream>
+#include <string>
+#include <map>
+
+namespace slic
+{
+  /**
+   * @class Logger
+   * @brief A simple class for printing log messages to an ostream.
+   */
+  class Logger
+  {
+  public:
+    Logger(const std::string& name,
+	   const LogLevel& level = LogLevel::DEFAULT,
+	   std::ostream* os = &std::cout);
+
+  public:
+
+    void log(const LogLevel&, const char*);
+    void log(const LogLevel&, const std::string&);
+    void log(const char*);
+    void log(const std::string&);
+
+    const std::string& name()
+    {
+      return m_name;
+    }
+
+    static Logger* getLogger(const std::string& filename);
+
+    static void registerLogger(Logger* logger);
+
+  private:
+    std::string m_name;
+    LogLevel m_level;
+    std::ostream* m_os;
+    static std::map<std::string, Logger*> m_logs;
+  };
+};
+
+#endif

slic/src
LogLevel.cc 1.3 -> 1.4
diff -N LogLevel.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ LogLevel.cc	13 Oct 2005 01:28:04 -0000	1.4
@@ -0,0 +1,14 @@
+// $Header: /cvs/lcd/slic/src/LogLevel.cc,v 1.4 2005/10/13 01:28:04 jeremy Exp $
+#include "LogLevel.hh"
+
+namespace slic
+{
+  const LogLevel LogLevel::NONE    = LogLevel(eNone,    "NONE");
+  const LogLevel LogLevel::FATAL   = LogLevel(eFatal,   "FATAL");
+  const LogLevel LogLevel::ERROR   = LogLevel(eError,   "ERROR");
+  const LogLevel LogLevel::WARN    = LogLevel(eWarn,    "WARN");
+  const LogLevel LogLevel::DEBUG   = LogLevel(eDebug,   "DEBUG");
+  const LogLevel LogLevel::OKAY    = LogLevel(eOkay,    "OKAY");
+  const LogLevel LogLevel::VERBOSE = LogLevel(eVerbose, "VERBOSE");
+  const LogLevel LogLevel::DEFAULT = LogLevel(eOkay,    "DEFAULT");
+}

slic/src
Logger.cc 1.3 -> 1.4
diff -N Logger.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Logger.cc	13 Oct 2005 01:28:04 -0000	1.4
@@ -0,0 +1,82 @@
+// $Header: /cvs/lcd/slic/src/Logger.cc,v 1.4 2005/10/13 01:28:04 jeremy Exp $
+#include "Logger.hh"
+
+// slic
+#include "LogManager.hh"
+
+// std
+#include <iomanip>
+
+using std::setw;
+using std::left;
+
+namespace slic
+{
+  std::map<std::string, Logger*> Logger::m_logs;
+
+  Logger::Logger(const std::string& name,
+		 const LogLevel& level,
+		 std::ostream* os)
+    : m_name(name),
+      m_level(level),
+      m_os(os)
+  {
+    if ( os == 0 ) {
+      os = &std::cout;
+    }
+
+    registerLogger(this);
+  }
+
+  void Logger::log(const LogLevel& level, const char* mesg)
+  {
+    if ( level <= m_level ) {
+
+      /* Print log level. */
+      (*m_os) << setw(9)
+	      << left
+	      << ("[" + level.toString() + "]");
+
+      /* Print name of the logger. */
+      (*m_os) << "  "
+	      << setw(22)
+	      << left
+	      << ("[" + m_name + "]");
+
+      /* Print the message. */
+      (*m_os) << "  ["
+	      << mesg
+	      << "]";
+
+      (*m_os) << '\n';
+    }
+  }
+
+  void Logger::log(const LogLevel& level, const std::string& mesg)
+  {
+    log( level, mesg.c_str() );
+  }
+
+  void Logger::log(const char* mesg)
+  {
+    log( m_level, mesg );
+  }
+
+  void Logger::log(const std::string& mesg)
+  {
+    log( m_level, mesg );
+  }
+
+  Logger* Logger::getLogger(const std::string& filename)
+  {
+    return m_logs[filename];
+  }
+
+  void Logger::registerLogger(Logger* logger)
+  {
+    std::string filename = logger->name();
+    if ( m_logs[filename] == 0 ) {
+      m_logs[filename] = logger;
+    }
+  }
+};
CVSspam 0.2.8