1
0

2 کامیت‌ها fa8cc41116 ... 85a82c8461

نویسنده SHA1 پیام تاریخ
  JDierkse 85a82c8461 Change console logging to follow LogMask 11 ماه پیش
  JDierkse 2490dabc82 Update Makefiles 11 ماه پیش
3فایلهای تغییر یافته به همراه21 افزوده شده و 17 حذف شده
  1. 18 16
      Logging/Logging.cpp
  2. 1 1
      Makefiles
  3. 2 0
      include/Logging.h

+ 18 - 16
Logging/Logging.cpp

@@ -8,6 +8,8 @@
 
 namespace Logging {
 
+Severity::type loggingSeverity;
+
 void OpenLog()
 {
 	openlog(NULL, LOG_NDELAY | LOG_PID, LOG_USER);
@@ -20,55 +22,55 @@ void CloseLog()
 
 void SetLogMask(Severity::type severity)
 {
+	loggingSeverity = severity;
 	int level = static_cast<int>(severity);
 	setlogmask(LOG_UPTO(level));
 
 	switch (level)
 	{
 	case LOG_EMERG:
-		Log(Severity::Emergency, "LogMask set to Severity::Emergency\n");
+		Log(Severity::Emergency, "LogMask set to Severity::Emergency");
 		break;
 	case LOG_ALERT:
-		Log(Severity::Alert, "LogMask set to Severity::Alert\n");
+		Log(Severity::Alert, "LogMask set to Severity::Alert");
 		break;
 	case LOG_CRIT:
-		Log(Severity::Critical, "LogMask set to Severity::Critical\n");
+		Log(Severity::Critical, "LogMask set to Severity::Critical");
 		break;
 	case LOG_ERR:
-		Log(Severity::Error, "LogMask set to Severity::Error\n");
+		Log(Severity::Error, "LogMask set to Severity::Error");
 		break;
 	case LOG_WARNING:
-		Log(Severity::Warning, "LogMask set to Severity::Warning\n");
+		Log(Severity::Warning, "LogMask set to Severity::Warning");
 		break;
 	case LOG_NOTICE:
-		Log(Severity::Notice, "LogMask set to Severity::Notice\n");
+		Log(Severity::Notice, "LogMask set to Severity::Notice");
 		break;
 	case LOG_INFO:
-		Log(Severity::Notice, "LogMask set to Severity::Info\n");
+		Log(Severity::Notice, "LogMask set to Severity::Info");
 		break;
 	case LOG_DEBUG:
-		Log(Severity::Notice, "LogMask set to Severity::Debug\n");
+		Log(Severity::Notice, "LogMask set to Severity::Debug");
 		break;
 	}
 }
 
 void Log(Severity::type severity, const std::string& message)
 {
-	bool error = (severity < Severity::Warning);
-	bool debug = (severity == Severity::Debug);
-	std::ostream& output = error? std::cerr: std::cout;
+	syslog(static_cast<int>(severity), "%s", message.c_str());
+
+	if (severity > loggingSeverity)
+		return;
 
-	bool newline = StringAlgorithm::ends_with(message, "\n");
+	std::ostream& output = (severity < Severity::Warning)? std::cerr: std::cout;
 
-	if (debug)
+	if (severity == Severity::Debug)
 		output << "       ";
 
 	output << message;
 
-	if (!newline)
+	if (!StringAlgorithm::ends_with(message, "\n"))
 		output << std::endl;
-
-	syslog(static_cast<int>(severity), "%s", message.c_str());
 }
 
 } // namespace Logging

+ 1 - 1
Makefiles

@@ -1 +1 @@
-Subproject commit 4bcd6867800526e4483cd0ef3f475add2daab5e6
+Subproject commit 25568790824bea7883279ae5a92b3c655d535ac9

+ 2 - 0
include/Logging.h

@@ -31,6 +31,8 @@ public:
 	};
 };
 
+extern Severity::type loggingSeverity;
+
 void OpenLog();
 void CloseLog();
 void SetLogMask(Severity::type severity);