[Box Backup-commit] COMMIT r1225 - box/chris/merge/lib/common

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Sat, 16 Dec 2006 20:26:31 +0000


Author: chris
Date: 2006-12-16 20:26:31 +0000 (Sat, 16 Dec 2006)
New Revision: 1225

Modified:
   box/chris/merge/lib/common/Logging.cpp
   box/chris/merge/lib/common/Logging.h
Log:

 * Rename Loggers class to Logging, which looks nicer.
 * Fix type of "line" argument to loggers to int rather than std::string
   to match __LINE__
 * Define necessary static objects
 * Remove global condition on logging for now

(refs #3)


Modified: box/chris/merge/lib/common/Logging.cpp
===================================================================
--- box/chris/merge/lib/common/Logging.cpp	2006-12-16 18:47:38 UTC (rev 1224)
+++ box/chris/merge/lib/common/Logging.cpp	2006-12-16 20:26:31 UTC (rev 1225)
@@ -15,11 +15,17 @@
 
 #include "Logging.h"
 
-bool Loggers::sLogToSyslog  = false;
-bool Loggers::sLogToConsole = false;
-bool Loggers::sContextSet   = false;
+bool Logging::sLogToSyslog  = false;
+bool Logging::sLogToConsole = false;
+bool Logging::sContextSet   = false;
 
-void Loggers::ToSyslog(bool enabled)
+std::vector<Logger*> Logging::sLoggers;
+std::string Logging::sContext;
+Console    Logging::sConsole;
+Syslog     Logging::sSyslog;
+Log::Level  Logging::sGlobalLevel;
+
+void Logging::ToSyslog(bool enabled)
 {
 	if (!sLogToSyslog && enabled)
 	{
@@ -34,7 +40,7 @@
 	sLogToSyslog = enabled;
 }
 
-void Loggers::ToConsole(bool enabled)
+void Logging::ToConsole(bool enabled)
 {
 	if (!sLogToConsole && enabled)
 	{
@@ -49,17 +55,17 @@
 	sLogToConsole = enabled;
 }
 
-void Loggers::FilterConsole(Log::Level level)
+void Logging::FilterConsole(Log::Level level)
 {
 	sConsole.Filter(level);
 }
 
-void Loggers::FilterSyslog(Log::Level level)
+void Logging::FilterSyslog(Log::Level level)
 {
 	sSyslog.Filter(level);
 }
 
-void Loggers::Add(Logger* pNewLogger)
+void Logging::Add(Logger* pNewLogger)
 {
 	for (std::vector<Logger*>::iterator i = sLoggers.begin();
 		i != sLoggers.end(); i++)
@@ -73,7 +79,7 @@
 	sLoggers.insert(sLoggers.begin(), pNewLogger);
 }
 
-void Loggers::Remove(Logger* pOldLogger)
+void Logging::Remove(Logger* pOldLogger)
 {
 	for (std::vector<Logger*>::iterator i = sLoggers.begin();
 		i != sLoggers.end(); i++)
@@ -86,8 +92,8 @@
 	}
 }
 
-void Loggers::Log(Log::Level level, const std::string& rFile, 
-	const std::string& rLine, const std::string& rMessage)
+void Logging::Log(Log::Level level, const std::string& rFile, 
+	int line, const std::string& rMessage)
 {
 	std::string newMessage;
 	
@@ -101,7 +107,7 @@
 	for (std::vector<Logger*>::iterator i = sLoggers.begin();
 		i != sLoggers.end(); i++)
 	{
-		bool result = (*i)->Log(level, rFile, rLine, newMessage);
+		bool result = (*i)->Log(level, rFile, line, newMessage);
 		if (!result)
 		{
 			return;
@@ -109,18 +115,18 @@
 	}
 }
 
-void Loggers::SetContext(std::string context)
+void Logging::SetContext(std::string context)
 {
 	sContext = context;
 	sContextSet = true;
 }
 
-void Loggers::ClearContext()
+void Logging::ClearContext()
 {
 	sContextSet = false;
 }
 
-void Loggers::SetProgramName(const std::string& rProgramName)
+void Logging::SetProgramName(const std::string& rProgramName)
 {
 	for (std::vector<Logger*>::iterator i = sLoggers.begin();
 		i != sLoggers.end(); i++)
@@ -130,7 +136,7 @@
 }
 
 bool Console::Log(Log::Level level, const std::string& rFile, 
-	const std::string& rLine, std::string& rMessage)
+	int line, std::string& rMessage)
 {
 	if (level > GetLevel())
 	{
@@ -144,13 +150,13 @@
 		target = stderr;
 	}
 	
-	fprintf(target, "%s", rMessage.c_str());
+	fprintf(target, "%s\n", rMessage.c_str());
 	
 	return true;
 }
 
 bool Syslog::Log(Log::Level level, const std::string& rFile, 
-	const std::string& rLine, std::string& rMessage)
+	int line, std::string& rMessage)
 {
 	if (level > GetLevel())
 	{

Modified: box/chris/merge/lib/common/Logging.h
===================================================================
--- box/chris/merge/lib/common/Logging.h	2006-12-16 18:47:38 UTC (rev 1224)
+++ box/chris/merge/lib/common/Logging.h	2006-12-16 20:26:31 UTC (rev 1225)
@@ -13,6 +13,7 @@
 #include <sstream>
 #include <vector>
 
+/*
 #define BOX_LOG(level, stuff) \
 { \
     if(Log::sMaxLoggingLevelForAnyOutput >= level) \
@@ -21,7 +22,15 @@
         Log::Write(level, __FILE__, __LINE__, line.str()); \
     } \
 }
+*/
 
+#define BOX_LOG(level, stuff) \
+{ \
+	std::ostringstream line; \
+	line << stuff; \
+	Logging::Log(level, __FILE__, __LINE__, line.str()); \
+}
+
 #define BOX_FATAL(stuff)   BOX_LOG(Log::FATAL,   stuff)
 #define BOX_ERROR(stuff)   BOX_LOG(Log::ERROR,   stuff)
 #define BOX_WARNING(stuff) BOX_LOG(Log::WARNING, stuff)
@@ -41,7 +50,7 @@
 //
 // Class
 //		Name:    Logger
-//		Purpose: Abstract class (interface) for log targets
+//		Purpose: Abstract base class for log targets
 //		Created: 2006/12/16
 //
 // --------------------------------------------------------------------------
@@ -56,7 +65,7 @@
 	virtual ~Logger() { }
 	
 	virtual bool Log(Log::Level level, const std::string& rFile, 
-		const std::string& rLine, std::string& rMessage) = 0;
+		int line, std::string& rMessage) = 0;
 	
 	void Filter(Log::Level level)
 	{
@@ -74,7 +83,7 @@
 // Class
 //		Name:    Console
 //		Purpose: Console logging target
-//		Created: 2006/12/12
+//		Created: 2006/12/16
 //
 // --------------------------------------------------------------------------
 
@@ -82,7 +91,7 @@
 {
 	public:
 	virtual bool Log(Log::Level level, const std::string& rFile, 
-		const std::string& rLine, std::string& rMessage);
+		int line, std::string& rMessage);
 	virtual const char* GetType() { return "Console"; }
 	virtual void SetProgramName(const std::string& rProgramName) { }
 };
@@ -92,7 +101,7 @@
 // Class
 //		Name:    Syslog
 //		Purpose: Syslog (or Windows Event Viewer) logging target
-//		Created: 2006/12/12
+//		Created: 2006/12/16
 //
 // --------------------------------------------------------------------------
 
@@ -103,7 +112,7 @@
 	virtual ~Syslog();
 	
 	virtual bool Log(Log::Level level, const std::string& rFile, 
-		const std::string& rLine, std::string& rMessage);
+		int line, std::string& rMessage);
 	virtual const char* GetType() { return "Syslog"; }
 	virtual void SetProgramName(const std::string& rProgramName);
 };
@@ -111,14 +120,14 @@
 // --------------------------------------------------------------------------
 //
 // Class
-//		Name:    Log
+//		Name:    Logging
 //		Purpose: Static logging helper, keeps track of enabled loggers
 //			 and distributes log messages to them.
-//		Created: 2006/12/12
+//		Created: 2006/12/16
 //
 // --------------------------------------------------------------------------
 
-class Loggers
+class Logging
 {
 	private:
 	static std::vector<Logger*> sLoggers;
@@ -138,7 +147,7 @@
 	static void Add    (Logger* pNewLogger);
 	static void Remove (Logger* pOldLogger);
 	static void Log(Log::Level level, const std::string& rFile, 
-		const std::string& rLine, const std::string& rMessage);
+		int line, const std::string& rMessage);
 	static void SetContext(std::string context);
 	static void ClearContext();
 	static void SetGlobalLevel(Log::Level level) { sGlobalLevel = level; }