1. Sylvain Rouquette
  2. pyGAP

Commits

Sylvain Rouquette  committed 4f5ae81

added more log options.

  • Participants
  • Parent commits 80c9e7d
  • Branches input

Comments (0)

Files changed (2)

File game/inc/common/log.h

View file
  • Ignore whitespace
 #include <string>
 
 
-#define LOG(...)                { if (log_) log_->write(__VA_ARGS__); }
+#define LOG(...)                { if (log_) log_->write(common::Log::LOG_DEBUG, __VA_ARGS__); }
+#define LOG_I(...)              { if (log_) log_->write(common::Log::LOG_INFO, __VA_ARGS__); }
+#define LOG_W(...)              { if (log_) log_->write(common::Log::LOG_WARNING, __VA_ARGS__); }
+#define LOG_E(...)              { if (log_) log_->write(common::Log::LOG_ERROR, __VA_ARGS__); }
 
 
 namespace common {
 class Log {
 public:
 
-    enum debug_level_e {
+    enum log_level_e {
         LOG_DEBUG,
+        LOG_INFO,
         LOG_WARNING,
         LOG_ERROR
     };
     static Log* get(const char* context);
     static void clear();
 
-    void write(const char* format, ...);
-    //void write(int level, const char* format, ...);
+    void write(log_level_e log_level, const char* format, ...);
+    void set_log_threshold(log_level_e log_level=LOG_DEBUG);
 
 private:
     Log(const char* context);
 
     char*   buffer_;
     int     context_length_;
+    log_level_e threshold_;
 
     typedef std::map<std::string, Log*> log_map_t;
     static log_map_t    allocated_;
 
 #else // defined(DEBUG)
 
-#define LOG(...)                {}
+#define LOG(...)        {}
+#define LOG_I(...)      {}
+#define LOG_W(...)      {}
+#define LOG_E(...)      {}
 
 #endif // defined(DEBUG)
 

File game/src/common/log.cpp

View file
  • Ignore whitespace
 
 
 Log::Log(const char* context) :
-    context_length_(0)
+    context_length_(0),
+    threshold_(Log::LOG_DEBUG)
 {
     buffer_ = new char [LOG_BUFFER_SIZE];
 
 }
 
 
-void Log::write(const char* format, ...) {
+void Log::write(Log::log_level_e log_level, const char* format, ...) {
+    if (threshold_ > log_level)
+        return;
+
+    switch (log_level) {
+        case LOG_DEBUG:
+            printf("_D_ ");
+        case LOG_INFO:
+            printf("_I_ ");
+        case LOG_WARNING:
+            printf("*W* ");
+        case LOG_ERROR:
+            printf("*E* ");
+    }
+
     va_list arg_list;
     va_start(arg_list, format);
     vsnprintf(buffer_ + context_length_,
               LOG_BUFFER_SIZE - context_length_,
               format, arg_list);
     va_end(arg_list);
+
     printf("%s", buffer_);
     fflush(stdout);
 }