[Swift-commit] cog r3989

swift at ci.uchicago.edu swift at ci.uchicago.edu
Thu Jun 26 15:00:04 CDT 2014


------------------------------------------------------------------------
r3989 | timgarmstrong | 2014-06-26 14:57:43 -0500 (Thu, 26 Jun 2014) | 1 line

Support logging from pure C interface
------------------------------------------------------------------------
Index: modules/provider-coaster-c-client/src/Logger.cpp
===================================================================
--- modules/provider-coaster-c-client/src/Logger.cpp	(revision 3988)
+++ modules/provider-coaster-c-client/src/Logger.cpp	(working copy)
@@ -18,8 +18,8 @@
 
 Logger::Logger(ostream& pout) {
 	out = &pout;
-	level = NONE;
-        threshold = INFO; // Only show info and higher by default
+	level = COASTER_LOG_NONE;
+	threshold = COASTER_LOG_INFO; // Only show info and higher by default
 	file = "<unknown>";
 	startOfItem = true;
 }
@@ -27,32 +27,32 @@
 Logger::~Logger() {
 }
 
-Logger& Logger::operator<< (Level plevel) {
+Logger& Logger::operator<< (CoasterLogLevel plevel) {
 	setLevel(plevel);
 	return *this;
 }
 
-void Logger::setLevel(Level plevel) {
+void Logger::setLevel(CoasterLogLevel plevel) {
 	level = plevel;
 	strLevel = levelToStr(level);
 }
 
-void Logger::setThreshold(Level plevel) {
+void Logger::setThreshold(CoasterLogLevel plevel) {
 	threshold = plevel;
 }
 
 
-const char* Logger::levelToStr(Level level) {
+const char* Logger::levelToStr(CoasterLogLevel level) {
 	switch (level) {
-		case NONE:
+		case COASTER_LOG_NONE:
 			return "NONE ";
-		case ERROR:
+		case COASTER_LOG_ERROR:
 			return "ERROR";
-		case WARN:
+		case COASTER_LOG_WARN:
 			return "WARN ";
-		case INFO:
+		case COASTER_LOG_INFO:
 			return "INFO ";
-		case DEBUG:
+		case COASTER_LOG_DEBUG:
 			return "DEBUG";
 		default:
 			return "?????";
@@ -113,7 +113,7 @@
 	 return *this;
 }
 
-void Logger::log(Level level, const char* fileName, const char* msg) {
+void Logger::log(CoasterLogLevel level, const char* fileName, const char* msg) {
 	if (level >= threshold) {
 		setLevel(level);
 		setFile(fileName);
@@ -122,7 +122,7 @@
 		commitBuffer();
 	}
 }
-void Logger::log(Level level, const char* fileName, string msg) {
+void Logger::log(CoasterLogLevel level, const char* fileName, string msg) {
 	if (level >= threshold) {
 		setLevel(level);
 		setFile(fileName);
Index: modules/provider-coaster-c-client/src/coasters.cpp
===================================================================
--- modules/provider-coaster-c-client/src/coasters.cpp	(revision 3988)
+++ modules/provider-coaster-c-client/src/coasters.cpp	(working copy)
@@ -615,3 +615,10 @@
   // TODO: handle specific types, e.g. bad_alloc
   return COASTER_ERROR_UNKNOWN;
 }
+
+coaster_rc coaster_set_log_threshold(coaster_log_level threshold) {
+  
+  Logger::singleton().setThreshold(threshold);
+
+  return COASTER_SUCCESS;
+}
Index: modules/provider-coaster-c-client/src/Logger.h
===================================================================
--- modules/provider-coaster-c-client/src/Logger.h	(revision 3988)
+++ modules/provider-coaster-c-client/src/Logger.h	(working copy)
@@ -14,38 +14,46 @@
 #include <fstream>
 #include <sstream>
 #include <string>
+
+#include "coaster-defs.h"
 #include "Lock.h"
 
 namespace Coaster {
 
 class Logger: public std::ostream {
 	public:
-		enum Level { NONE = -1, DEBUG = 0, INFO = 1, WARN = 2, ERROR = 3, FATAL = 4 };
 		static Logger* instance;
+
+		static const CoasterLogLevel NONE = COASTER_LOG_NONE;
+		static const CoasterLogLevel DEBUG = COASTER_LOG_DEBUG;
+		static const CoasterLogLevel INFO = COASTER_LOG_INFO;
+		static const CoasterLogLevel WARN = COASTER_LOG_WARN;
+		static const CoasterLogLevel ERROR = COASTER_LOG_ERROR;
+		static const CoasterLogLevel FATAL = COASTER_LOG_FATAL;
 	private:
 		std::ostream* out;
 		std::stringstream buffer;
-		Level level, threshold;
+		CoasterLogLevel level, threshold;
 		const char* file;
 		const char* strLevel;
 		char ts[TS_LEN + 1];
 		bool startOfItem;
 		Lock lock;
 		
-                /* Disable default copy constructor */
+		/* Disable default copy constructor */
 		Logger(const Logger&);
 		/* Disable default assignment */
 		Logger& operator=(const Logger&);
 	protected:
 		Logger(std::ostream& out);
-		void setLevel(Level level);
-		const char* levelToStr(Level level);
+		void setLevel(CoasterLogLevel level);
+		const char* levelToStr(CoasterLogLevel level);
 		void header();
 		char* timeStamp();
 		void commitBuffer();
 	public:
 		virtual ~Logger();
-		Logger& operator<< (Level level);
+		Logger& operator<< (CoasterLogLevel level);
 		Logger& operator<< (const std::string& str);
 		Logger& operator<< (const std::string* str);
 		Logger& operator<< (const char* str);
@@ -54,10 +62,10 @@
 		Logger& operator<< (Logger& ( *pf )(Logger&));
 		Logger& setFile(const char* file);
 		void endItem();
-		void log(Level level, const char* fileName, const char* msg);
-		void log(Level level, const char* fileName, std::string msg);
+		void log(CoasterLogLevel level, const char* fileName, const char* msg);
+		void log(CoasterLogLevel level, const char* fileName, std::string msg);
 
-		void setThreshold(Level level);
+		void setThreshold(CoasterLogLevel level);
 
 		static Logger& singleton();
 };
Index: modules/provider-coaster-c-client/src/coasters.h
===================================================================
--- modules/provider-coaster-c-client/src/coasters.h	(revision 3988)
+++ modules/provider-coaster-c-client/src/coasters.h	(working copy)
@@ -311,6 +311,8 @@
  */
 const char *coaster_last_err_info(void);
 
+coaster_rc coaster_set_log_threshold(coaster_log_level threshold);
+
 #ifdef __cplusplus
 } // extern "C"
 #endif



More information about the Swift-commit mailing list