Kaya Kupferschmidt avatar Kaya Kupferschmidt committed b2d1c4d

Fixed mutex locking in logging

Comments (0)

Files changed (9)

source/libs/magnum_logging/source/magnum/logging/AbstractLogger.cpp

  */
 void AbstractLogger::logDebug(const String& msg)
 {
-	m_Mutex.lock();
-	try {
-		logRecord(LogRecord(LogLevel::Debug,getCategory(),msg));
-    }
-    catch(...) {
-	}
-	m_Mutex.unlock();
+    logRecord(LogRecord(LogLevel::Debug,getCategory(),msg));
 }
 
 
  */
 void AbstractLogger::logTrace(const String& msg)
 {
-	m_Mutex.lock();
-	try {
-		logRecord(LogRecord(LogLevel::Trace,getCategory(),msg));
-    }
-    catch(...) {
-	}
-	m_Mutex.unlock();
+    logRecord(LogRecord(LogLevel::Trace,getCategory(),msg));
 }
 
 
  */
 void AbstractLogger::logInfo(const String& msg)
 {
-	m_Mutex.lock();
-	try {
-		logRecord(LogRecord(LogLevel::Info,getCategory(),msg));
-    }
-    catch(...) {
-	}
-	m_Mutex.unlock();
+    logRecord(LogRecord(LogLevel::Info,getCategory(),msg));
 }
 
 
  */
 void AbstractLogger::logNote(const String& msg)
 {
-	m_Mutex.lock();
-	try {
-		logRecord(LogRecord(LogLevel::Note,getCategory(),msg));
-    }
-    catch(...) {
-	}
-	m_Mutex.unlock();
+    logRecord(LogRecord(LogLevel::Note,getCategory(),msg));
 }
 
 
  */
 void AbstractLogger::logWarning(const String& msg)
 {
-	m_Mutex.lock();
-	try {
-		logRecord(LogRecord(LogLevel::Warning,getCategory(),msg));
-    }
-    catch(...) {
-	}
-	m_Mutex.unlock();
+    logRecord(LogRecord(LogLevel::Warning,getCategory(),msg));
 }
 
 
  */
 void AbstractLogger::logError(const String& msg)
 {
-	m_Mutex.lock();
-	try {
-		logRecord(LogRecord(LogLevel::Error,getCategory(),msg));
-    }
-    catch(...) {
-	}
-	m_Mutex.unlock();
+    logRecord(LogRecord(LogLevel::Error,getCategory(),msg));
 }
 
 
  */
 void AbstractLogger::logFatal(const String& msg)
 {
-	m_Mutex.lock();
-	try {
-		logRecord(LogRecord(LogLevel::Fatal,getCategory(),msg));
-    }
-    catch(...) {
-	}
-	m_Mutex.unlock();
+    logRecord(LogRecord(LogLevel::Fatal,getCategory(),msg));
 }
 
 } }

source/libs/magnum_logging/source/magnum/logging/AbstractLogger.h

 #define __MAGNUM_LOGGING_ABSTRACTLOGGER_H
 
 #include "magnum/logging/Logger.h"
-#include "magnum/system/Mutex.h"
 
 
 namespace magnum { namespace logging {
-using magnum::system::Mutex;
 
 
 /*--------------------------------------------------------------------------*/
 	virtual LogLevel::Level getLevel() const;
 	virtual LogLevel::Level getEffectiveLevel() const;
     virtual LogCategory getCategory() const;
-	
+
 private:
     LogCategory m_Category;
-    Mutex m_Mutex;
     LogLevel::Level m_Level;
 };
 

source/libs/magnum_logging/source/magnum/logging/AppendingLogger.h

 
 #include "magnum/object/Reference.h"
 #include "magnum/object/Array.h"
+#include "magnum/system/Mutex.h"
 #include "magnum/logging/HierarchicalLogger.h"
 #include "magnum/logging/Appender.h"
 
 namespace magnum { namespace logging {
 using magnum::object::Reference;
 using magnum::object::Array;
+using magnum::system::Mutex;
 
 
 /*--------------------------------------------------------------------------*/

source/libs/magnum_logging/source/magnum/logging/ConsoleLogger.cpp

     if (getLevel() > record.getLevel()) 
         return;
 
-	StringBuffer str;
-	str << "[" << LogLevel(record.getLevel()).toString()
-        << "][" << record.getCategory().getName()
-	    << "] " << record.getMessage() << "\n";
-	Err << str;
-	Err.flush();
+    m_Mutex.lock();
+    try {
+        StringBuffer str;
+        str << "[" << LogLevel(record.getLevel()).toString()
+            << "][" << record.getCategory().getName()
+            << "] " << record.getMessage() << "\n";
+        Err << str;
+        Err.flush();
+    }
+    catch(...) {
+    }
+    m_Mutex.unlock();
 }
 
 } }

source/libs/magnum_logging/source/magnum/logging/ConsoleLogger.h

 #ifndef __MAGNUM_LOGGING_CONSOLELOGGER_H
 #define __MAGNUM_LOGGING_CONSOLELOGGER_H
 
+#include "magnum/system/Mutex.h"
 #include "magnum/logging/AbstractLogger.h"
 
 
 namespace magnum { namespace logging {
+using magnum::system::Mutex;
+
 
 /*--------------------------------------------------------------------------*/
 /**
     virtual ~ConsoleLogger();
 	
     virtual void logRecord(const LogRecord& );
+
+private:
+    Mutex m_Mutex;
 };
 
 } }

source/libs/magnum_logging/source/magnum/logging/SimpleLogger.cpp

         return;
     if (m_Stream == Nil)
         return;
-        
-    StringBuffer strbuf;
-    strbuf << '[' << LogLevel(record.getLevel()).toString() << "] " << record.getMessage() << '\n';
-    m_Stream->write(strbuf.toLatin1().getData(), strbuf.getLength());
-    m_Stream->flush();
+
+    m_Mutex.lock();
+    try {
+        StringBuffer strbuf;
+        strbuf << '[' << LogLevel(record.getLevel()).toString() << "] " << record.getMessage() << '\n';
+        m_Stream->write(strbuf.toLatin1().getData(), strbuf.getLength());
+        m_Stream->flush();
+    }
+    catch(...) {
+    }
+    m_Mutex.unlock();
 }
 
 } }

source/libs/magnum_logging/source/magnum/logging/SimpleLogger.h

 #define __MAGNUM_LOGGING_SIMPLELOGGER_H
 
 #include "magnum/object/Reference.h"
+#include "magnum/system/Mutex.h"
 #include "magnum/io/OutputStream.h"
 #include "magnum/logging/AbstractLogger.h"
 
 namespace magnum { namespace logging {
 using magnum::object::Reference;
 using magnum::io::OutputStream;
-using magnum::logging::LogRecord;
-using magnum::logging::AbstractLogger;
+using magnum::system::Mutex;
 
 
 /*--------------------------------------------------------------------------*/
 	
 private:
 	Reference<OutputStream>	m_Stream;
+    Mutex m_Mutex;
 };
 
 } }

source/libs/magnum_logging/source/magnum/logging/StreamLogger.cpp

 {
 	if (m_Stream == Nil)
 		return;
+
+    m_Mutex.lock();
 	try {
         StringBuffer strbuf;
         strbuf << '[' << LogLevel(record.getLevel()).toString()
     }
     catch(...) {
 	}
+    m_Mutex.unlock();
 }
 
 } }

source/libs/magnum_logging/source/magnum/logging/StreamLogger.h

 #define __MAGNUM_LOGGING_STREAMLOGGER_H
 
 #include "magnum/object/Reference.h"
-#include "magnum/logging/AbstractLogger.h"
+#include "magnum/system/Mutex.h"
 #include "magnum/io/OutputStream.h"
 #include "magnum/filesystem/File.h"
 #include "magnum/filesystem/Path.h"
+#include "magnum/logging/AbstractLogger.h"
 
 
 namespace magnum { namespace logging {
 using magnum::filesystem::File;
 using magnum::filesystem::Path;
 using magnum::io::OutputStream;
+using magnum::system::Mutex;
 
 
 /*--------------------------------------------------------------------------*/
 	
 	inline OutputStream*	getStream() const;
 	
-	virtual void			logRecord(const LogRecord& );
+    virtual void logRecord(const LogRecord& );
 
 private:
 	Reference<OutputStream>	m_Stream;
-	Reference<File>			m_File;
+    Reference<File> m_File;
+    Mutex m_Mutex;
 };
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.