myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-210-


From: Francesco Pipita
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-210-gbcb6eb8
Date: Sun, 02 May 2010 16:51:46 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  bcb6eb8dfbd355060a73024b8aaa3d6b8b80e47e (commit)
       via  7ea20a520aacd3c9aef5f62a9089d4e425711738 (commit)
       via  7fc4c8d9ee1ea92306f9577aa44b61d7b0c52a2d (commit)
      from  6ca61b7efcd69043d6d44b15b8d72d80a1fd1dd7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit bcb6eb8dfbd355060a73024b8aaa3d6b8b80e47e
Merge: 7ea20a5 6ca61b7
Author: Francesco Pipita <address@hidden>
Date:   Sun May 2 18:51:16 2010 +0200

    Merge branch 'master' of ssh://git.sv.gnu.org/srv/git/myserver




commit 7ea20a520aacd3c9aef5f62a9089d4e425711738
Author: Francesco Pipita <address@hidden>
Date:   Sun May 2 18:44:30 2010 +0200

    Little optimization in the log-related methods of the LogManager.

diff --git a/myserver/include/log/log_manager.h 
b/myserver/include/log/log_manager.h
index 31230af..8b7a8e3 100644
--- a/myserver/include/log/log_manager.h
+++ b/myserver/include/log/log_manager.h
@@ -16,7 +16,7 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#ifndef LOG_MANAGER_H
+# ifndef LOG_MANAGER_H
 # define LOG_MANAGER_H
 
 # include "myserver.h"
diff --git a/myserver/include/log/stream/console_stream.h 
b/myserver/include/log/stream/console_stream.h
index e526d52..61ca481 100644
--- a/myserver/include/log/stream/console_stream.h
+++ b/myserver/include/log/stream/console_stream.h
@@ -32,7 +32,8 @@ class ConsoleStream : public LogStream
 {
 public:
   ConsoleStream (FiltersFactory*, u_long, Stream*, FiltersChain*);
-  virtual int setMode (LoggingLevel level);
+  virtual int initialize (LoggingLevel);
+  virtual int finalize ();
 };
 
 #endif
diff --git a/myserver/include/log/stream/log_stream.h 
b/myserver/include/log/stream/log_stream.h
index c36b134..65055f9 100644
--- a/myserver/include/log/stream/log_stream.h
+++ b/myserver/include/log/stream/log_stream.h
@@ -33,11 +33,6 @@ using namespace std;
 
 enum LoggingLevel
   {
-    /* The MYSERVER_LOG_MSG_PLAIN is only used within the
-     * LogManager class to print new lines with normal text
-     * attributes over the ConsoleStream.
-     */
-    MYSERVER_LOG_MSG_PLAIN,
     MYSERVER_LOG_MSG_INFO,
     MYSERVER_LOG_MSG_WARNING,
     MYSERVER_LOG_MSG_ERROR
@@ -49,8 +44,7 @@ enum LogStreamEvent
     MYSERVER_LOG_EVT_LOG,
     MYSERVER_LOG_EVT_CLOSE,
     MYSERVER_LOG_EVT_ADD_FILTER,
-    MYSERVER_LOG_EVT_CHOWN,
-    MYSERVER_LOG_EVT_SET_MODE
+    MYSERVER_LOG_EVT_CHOWN
   };
 
 class LogStream
@@ -70,13 +64,14 @@ public:
   int setCycle (u_long cycle);
   int needToCycle ();
   list<string>& getCycledStreams ();
-  virtual int log (const string & message);
+  virtual int log (const string & message, LoggingLevel);
   virtual u_long streamSize ();
   virtual int chown (int uid, int gid);
-  virtual int setMode (LoggingLevel level);
   virtual ~LogStream ();
 protected:
   virtual int streamCycle ();
+  virtual int initialize (LoggingLevel);
+  virtual int finalize ();
   int doCycle ();
   int write (const string &message);
   int resetFilters ();
diff --git a/myserver/src/log/log_manager.cpp b/myserver/src/log/log_manager.cpp
index b5bd4d4..492485b 100644
--- a/myserver/src/log/log_manager.cpp
+++ b/myserver/src/log/log_manager.cpp
@@ -475,17 +475,15 @@ LogManager::log (const void* owner, string & message, 
bool appendNL,
   mutex->lock ();
   try
     {
-      failure = notify (owner, MYSERVER_LOG_EVT_SET_MODE,
-                        static_cast<void*>(&level))
-        || notify (owner,MYSERVER_LOG_EVT_LOG, &message);
       if (appendNL)
         {
-          LoggingLevel l = MYSERVER_LOG_MSG_PLAIN;
-          failure |= (notify (owner, MYSERVER_LOG_EVT_SET_MODE,
-                              (static_cast<void*>(&l)))
-                      || notify (owner, MYSERVER_LOG_EVT_LOG,
-                                 (static_cast<void*>(&newline))));
+          message.append (newline);
         }
+
+      void* params[2];
+      params[0] = static_cast<void*>(&message);
+      params[1] = static_cast<void*>(&level);
+      failure = notify (owner, MYSERVER_LOG_EVT_LOG, params);
     }
   catch (...)
     {
@@ -521,19 +519,15 @@ LogManager::log (const void* owner, const string & type, 
string & message,
   mutex->lock ();
   try
     {
-      failure = notify (owner, type, MYSERVER_LOG_EVT_SET_MODE,
-                        static_cast<void*>(&level))
-        || notify (owner, type, MYSERVER_LOG_EVT_LOG,
-                   static_cast<void*>(&message));
-
       if (appendNL)
         {
-          LoggingLevel l = MYSERVER_LOG_MSG_PLAIN;
-          failure |= (notify (owner, MYSERVER_LOG_EVT_SET_MODE,
-                              (static_cast<void*>(&l)))
-                      || notify (owner, MYSERVER_LOG_EVT_LOG,
-                                 (static_cast<void*>(&newline))));
+          message.append (newline);
         }
+
+      void* params[2];
+      params[0] = static_cast<void*>(&message);
+      params[1] = static_cast<void*>(&level);
+      failure = notify (owner, type, MYSERVER_LOG_EVT_LOG, params);
     }
   catch (...)
     {
@@ -571,17 +565,15 @@ LogManager::log (const void* owner, const string & type, 
const string & location
   mutex->lock ();
   try
     {
-      failure = notify (owner, type, MYSERVER_LOG_EVT_SET_MODE, &level)
-        || notify (owner, type, MYSERVER_LOG_EVT_LOG, &message);
-
       if (appendNL)
         {
-          LoggingLevel l = MYSERVER_LOG_MSG_PLAIN;
-          failure |= notify (owner, MYSERVER_LOG_EVT_SET_MODE,
-                             (static_cast<void*>(&l)))
-            || notify (owner, MYSERVER_LOG_EVT_LOG,
-                       static_cast<void*>(&newline));
+          message.append (newline);
         }
+
+      void* params[2];
+      params[0] = static_cast<void*>(&message);
+      params[1] = static_cast<void*>(&level);
+      failure = notify (owner, type, location, MYSERVER_LOG_EVT_LOG, params);
     }
   catch (...)
     {
@@ -647,6 +639,7 @@ LogManager::log (const void* owner, const string & type, 
LoggingLevel level,
 {
   int failure = 0;
   ostringstream oss;
+  string message;
 
   if (level < this->level)
     return 1;
@@ -667,8 +660,7 @@ LogManager::log (const void* owner, const string & type, 
LoggingLevel level,
           time[len + 3] = '-';
           time[len + 4] = ' ';
           time[len + 5] = '\0';
-          string timestr (time);
-          failure |= notify (owner, MYSERVER_LOG_EVT_LOG, &timestr);
+          message.append (time);
         }
 
       while (*fmt)
@@ -709,14 +701,18 @@ LogManager::log (const void* owner, const string & type, 
LoggingLevel level,
           fmt++;
         }
 
-      string message = oss.str ();
-
-      failure = notify (owner, type, MYSERVER_LOG_EVT_SET_MODE,
-                        static_cast<void*>(&level))
-             || notify (owner, type, MYSERVER_LOG_EVT_LOG, &message);
+      message.append (oss.str ());
 
       if (appendNL)
-        failure |= notify (owner, type, MYSERVER_LOG_EVT_LOG, &newline);
+        {
+          message.append (newline);
+        }
+
+      void* params[2];
+      params[0] = static_cast<void*>(&message);
+      params[1] = static_cast<void*>(&level);
+
+      failure |= notify (owner, type, MYSERVER_LOG_EVT_LOG, params);
     }
   catch (...)
     {
diff --git a/myserver/src/log/stream/console_stream.cpp 
b/myserver/src/log/stream/console_stream.cpp
index 01ddbad..f7c02b2 100644
--- a/myserver/src/log/stream/console_stream.cpp
+++ b/myserver/src/log/stream/console_stream.cpp
@@ -25,31 +25,21 @@ ConsoleStream::ConsoleStream (FiltersFactory* ff, u_long 
cycle, Stream* out,
 {
 }
 
-/*!
- * Change the console text attributes according to the logging level.
- * \param level The logging level.
- * \return 0 on success, 1 on error.
- */
 int
-ConsoleStream::setMode (LoggingLevel level)
+ConsoleStream::initialize (LoggingLevel level)
 {
-  mutex->lock ();
-  int success = 1;
   Console* c = dynamic_cast<Console*>(out);
-  if (level == MYSERVER_LOG_MSG_PLAIN)
-    {
-      success = c->setColor ("reset", "reset");
-    }
-  else
-    {
-      Server* server = Server::getInstance ();
-      LogManager* lm = server->getLogManager ();
-      map<string, string> userColors = server->getConsoleColors ();
-      map<LoggingLevel, string> levels = lm->getLoggingLevels ();
-      string fg_color = userColors[levels[level] + "_fg"];
-      string bg_color = userColors[levels[level] + "_bg"];
-      success = c->setColor (fg_color, bg_color);
-    }
-  mutex->unlock ();
-  return success;
+  Server* server = Server::getInstance ();
+  LogManager* lm = server->getLogManager ();
+  map<string, string> userColors = server->getConsoleColors ();
+  map<LoggingLevel, string> levels = lm->getLoggingLevels ();
+  string fg_color = userColors[levels[level] + "_fg"];
+  string bg_color = userColors[levels[level] + "_bg"];
+  return c->setColor (fg_color, bg_color);
+}
+
+int
+ConsoleStream::finalize ()
+{
+  return static_cast<Console*>(out)->reset ();
 }
diff --git a/myserver/src/log/stream/log_stream.cpp 
b/myserver/src/log/stream/log_stream.cpp
index 5f11eb6..1b1a1e1 100644
--- a/myserver/src/log/stream/log_stream.cpp
+++ b/myserver/src/log/stream/log_stream.cpp
@@ -47,24 +47,28 @@ LogStream::resetFilters ()
 }
 
 int
-LogStream::log (const string & message)
+LogStream::log (const string & message, LoggingLevel level)
 {
   int success = 0;
+
   mutex->lock ();
+
   try
     {
       if (needToCycle ())
-        success = doCycle () || write (message);
+        success = doCycle () || initialize (level) || write (message) ||
+          finalize ();
       else
-        success = write (message);
-
-      mutex->unlock ();
+        success = initialize (level) || write (message) || finalize ();
     }
   catch (...)
     {
       mutex->unlock ();
       throw;
     }
+
+  mutex->unlock ();
+
   return success;
 }
 
@@ -122,7 +126,7 @@ LogStream::close ()
     {
       success = 1;
       isOpened = fc->flush (&nbw) || out->close ();
-      if (! isOpened)
+      if (!isOpened)
         success = 0;
 
       mutex->unlock ();
@@ -145,7 +149,11 @@ LogStream::update (LogStreamEvent evt, void* message, 
void* reply)
       return !isOpened || setCycle (*static_cast<u_long*>(message));
 
     case MYSERVER_LOG_EVT_LOG:
-      return !isOpened || log (*static_cast<string*>(message));
+      {
+        string& logMsg = 
*static_cast<string*>(static_cast<void**>(message)[0]);
+        LoggingLevel lvl = 
*static_cast<LoggingLevel*>(static_cast<void**>(message)[1]);
+        return !isOpened || log (logMsg, lvl);
+      }
 
     case MYSERVER_LOG_EVT_CLOSE:
       return !isOpened || close ();
@@ -157,11 +165,6 @@ LogStream::update (LogStreamEvent evt, void* message, 
void* reply)
     case MYSERVER_LOG_EVT_CHOWN:
         return !isOpened || chown (static_cast<int*>(message)[0],
                                    static_cast<int*>(message)[1]);
-
-    case MYSERVER_LOG_EVT_SET_MODE:
-        return !isOpened
-          || setMode (*static_cast<LoggingLevel*>(message));
-
     }
 
   return 1;
@@ -252,7 +255,13 @@ LogStream::chown (int uid, int gid)
 }
 
 int
-LogStream::setMode (LoggingLevel level)
+LogStream::initialize (LoggingLevel level)
+{
+  return 0;
+}
+
+int 
+LogStream::finalize ()
 {
   return 0;
 }
diff --git a/myserver/tests/test_file_stream.cpp 
b/myserver/tests/test_file_stream.cpp
index a6ff1a5..e8c91ab 100644
--- a/myserver/tests/test_file_stream.cpp
+++ b/myserver/tests/test_file_stream.cpp
@@ -66,6 +66,7 @@ public:
     string message;
     string message2;
     LogStream* ls;
+    LoggingLevel level = MYSERVER_LOG_MSG_INFO;
     try
       {
         FilesUtility::deleteFile ("foo");
@@ -84,8 +85,8 @@ public:
 
     ls = fsc->create (ff, "foo", filters, 10);
     CPPUNIT_ASSERT (ls);
-    CPPUNIT_ASSERT (!ls->log (message));
-    CPPUNIT_ASSERT (!ls->log (message2));
+    CPPUNIT_ASSERT (!ls->log (message, level));
+    CPPUNIT_ASSERT (!ls->log (message2, level));
     ls->close ();
     File f;
     f.openFile ("foo", File::READ | File::OPEN_IF_EXISTS);
@@ -122,6 +123,7 @@ public:
     string message1;
     string message2;
     ostringstream oss;
+    LoggingLevel level = MYSERVER_LOG_MSG_INFO;
 
     oss << "message1" << endl;
     message1.assign (oss.str ());
@@ -138,13 +140,13 @@ public:
       }
     ls = fsc->create (ff, "foo", filters, 0);
     CPPUNIT_ASSERT (ls);
-    ls->log (message1);
+    ls->log (message1, level);
     ls->close ();
     delete ls;
 
     ls = fsc->create (ff, "foo", filters, 0);
     CPPUNIT_ASSERT (ls);
-    ls->log (message2);
+    ls->log (message2, level);
     ls->close ();
     delete ls;
 



commit 7fc4c8d9ee1ea92306f9577aa44b61d7b0c52a2d
Author: Francesco Pipita <address@hidden>
Date:   Sun May 2 17:02:57 2010 +0200

    Added doxygen information about the suppressWarnings parameter to the add 
method.

diff --git a/myserver/src/log/log_manager.cpp b/myserver/src/log/log_manager.cpp
index 8ec355f..b5bd4d4 100644
--- a/myserver/src/log/log_manager.cpp
+++ b/myserver/src/log/log_manager.cpp
@@ -110,6 +110,7 @@ LogManager::clear ()
  * \param location The location string for the new LogStream.
  * \param filters A list of strings, each representing a valid filter name.
  * \param cycle The cycle value for the LogStream.
+ * \param suppressWarnings by default it is 0, meaning don't suppress warnings.
  *
  * \return 0 on success, 1 on error.
  */

-----------------------------------------------------------------------

Summary of changes:
 myserver/include/log/log_manager.h           |    2 +-
 myserver/include/log/stream/console_stream.h |    3 +-
 myserver/include/log/stream/log_stream.h     |   13 ++----
 myserver/src/log/log_manager.cpp             |   65 ++++++++++++-------------
 myserver/src/log/stream/console_stream.cpp   |   38 ++++++---------
 myserver/src/log/stream/log_stream.cpp       |   35 +++++++++-----
 myserver/tests/test_file_stream.cpp          |   10 ++--
 7 files changed, 80 insertions(+), 86 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

[Prev in Thread] Current Thread [Next in Thread]