From 20ecef1f7091f4a6945cd0b43aedfc96af5d87e8 Mon Sep 17 00:00:00 2001
From: Marco Biasini <marco.biasini@unibas.ch>
Date: Fri, 1 Oct 2010 13:34:10 +0200
Subject: [PATCH] added SCRIPT logging level

---
 modules/base/doc/logging.rst        | 18 +++++++++++-------
 modules/base/pymod/export_logger.cc |  2 ++
 modules/base/src/log.hh             | 10 ++++++----
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/modules/base/doc/logging.rst b/modules/base/doc/logging.rst
index 8e7ebe76d..1a81d4794 100644
--- a/modules/base/doc/logging.rst
+++ b/modules/base/doc/logging.rst
@@ -19,10 +19,10 @@ OpenStructure has a logging system going beyond what print statements can offer.
 .. note::
 
   In C++, the logging facility is implemented as a set of macros, called
-  `LOG_ERROR`, `LOG_WARNING`, `LOG_INFO`, `LOG_VERBOSE`, `LOG_DEBUG` and
-  `LOG_TRACE`. The last two are only active when compiling with debugging 
-  symbols. When debugging symbols are off, they expand to an empty macro and 
-  thus don't create any overhead.
+  `LOG_ERROR`, `LOG_WARNING`, `LOG_SCRIPT`, `LOG_INFO`, `LOG_VERBOSE`,
+  `LOG_DEBUG` and `LOG_TRACE`. The last two are only active when compiling with 
+  debugging symbols. When debugging symbols are off, they expand to an empty 
+  macro and thus don't create any overhead.
 
 
 Verbosity Level
@@ -34,7 +34,7 @@ You can change the verbosity level  with the following two methods:
 
   Change the verbosity level to the given integer value. All log events 
   which have a severity above verbosity will be ignored. By default, the log 
-  level is 2, meaning that errors, warnings and info logging events are 
+  level is 2, meaning that errors, warnings and script logging events are 
   visible.
 
   :type  verbosity: :class:`int`
@@ -140,10 +140,14 @@ WARNING:
   Diagnose potential problems that do not abort the execution, but may 
   point to a misconfiguration/misuse. This level is turned on by default.
 
+SCRIPT: 
+  Logging level that should be used from scripts, e.g. to report progress. These 
+  logging messages are turned on by default.
+
 INFO: 
   Informative and important messages that summarize a complex command, such as 
   information on a loaded file, or results from an algorithm. These logging 
-  messages are turned on by default.
+  messages are not turned on by default.
 
 VERBOSE: 
   Grey-zone between user and developer need, and perhaps the hardest to get
@@ -178,7 +182,7 @@ terminal (or the python shell in DNG). The logger also prints the current time.
       ost.LogSink.__init__(self)
 
     def LogMessage(self, message, severity):
-      levels=['ERROR', 'WARNING', 'INFO', 
+      levels=['ERROR', 'WARNING', 'SCRIPT', 'INFO', 
               'VERBOSE', 'DEBUG', 'TRACE']
       level=levels[severity]
       print '%s[%s]: %s' % (level, str(datetime.datetime.now()), message),
diff --git a/modules/base/pymod/export_logger.cc b/modules/base/pymod/export_logger.cc
index 7f29c16e5..5ffb101bd 100644
--- a/modules/base/pymod/export_logger.cc
+++ b/modules/base/pymod/export_logger.cc
@@ -73,6 +73,7 @@ void pop_log_sink()
 
 void log_error(const String& m) {LOG_ERROR(m);}
 void log_warning(const String& m) {LOG_WARNING(m);}
+void log_script(const String& m) {LOG_SCRIPT(m);}
 void log_info(const String& m) {LOG_INFO(m);}
 void log_verbose(const String& m) {LOG_VERBOSE(m);}
 
@@ -109,6 +110,7 @@ void export_Logger()
   def("LogError",log_error);
   def("LogWarning",log_warning);
   def("LogInfo",log_info);
+  def("LogScript", log_script)
   def("LogVerbose", log_verbose);
   
   // this relatively ugly construct is required to work around a problem with
diff --git a/modules/base/src/log.hh b/modules/base/src/log.hh
index 4ed5c7ed5..b535346f3 100644
--- a/modules/base/src/log.hh
+++ b/modules/base/src/log.hh
@@ -35,10 +35,11 @@ public:
   enum LogLevel {
     QUIET   =0,
     WARNING =1,
-    INFO    =2,
-    VERBOSE =3,
-    DEBUG   =4,
-    TRACE   =5
+    SCRIPT  =2,
+    INFO    =3,
+    VERBOSE =4,
+    DEBUG   =5,
+    TRACE   =6
   };
 
   void PushVerbosityLevel(int level);
@@ -82,6 +83,7 @@ private:
 
 #define LOG_ERROR(m) OST_DO_LOGGING_(m, ::ost::Logger::QUIET)
 #define LOG_WARNING(m) OST_DO_LOGGING_(m, ::ost::Logger::WARNING)
+#define LOG_SCRIPT(m) OST_DO_LOGGING_(m, ::ost::Logger::SCRIPT)
 #define LOG_INFO(m) OST_DO_LOGGING_(m, ::ost::Logger::INFO)
 #define LOG_VERBOSE(m) OST_DO_LOGGING_(m, ::ost::Logger::VERBOSE)
 #ifdef NDEBUG
-- 
GitLab