Author: sh-sh-sh
Date: Fri Jan 11 18:43:09 2008
New Revision: 43565
URL: http://svn.opensuse.org/viewcvs/yast?rev=43565&view=rev
Log:
separating UI logging
Added:
trunk/core/libyui/src/YUILog.h
Added: trunk/core/libyui/src/YUILog.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YUILog.h?rev=43565&view=auto
==============================================================================
--- trunk/core/libyui/src/YUILog.h (added)
+++ trunk/core/libyui/src/YUILog.h Fri Jan 11 18:43:09 2008
@@ -0,0 +1,141 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YUILog.h
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+#ifndef YUILog_h
+
+#ifndef YUILogComponent
+#error Missing #define YUILogComponent "myComponent"
+#endif
+
+#include <iosfwd>
+#include <iostream>
+
+//
+// Macros for Application use.
+//
+// They all return a std::ostream & for use with operator<<().
+// #define YUILogComponent before including this header file.
+//
+// #define YUILogComponent "myComponent"
+// #include
+//
+// ...
+// yuiDebug() << "Creating widget" << widget << endl;
+// yuiError() << "No widget with ID " << id << endl;
+//
+// Milestone, Warning and Error are always logged, Debug only when enabled.
+//
+
+#define yuiDebug() YUILog::debug ( YUILogComponent, __FILE__, __LINE__, __FUNCTION__ )
+#define yuiMilestone() YUILog::milestone( YUILogComponent, __FILE__, __LINE__, __FUNCTION__ )
+#define yuiWarning() YUILog::warning ( YUILogComponent, __FILE__, __LINE__, __FUNCTION__ )
+#define yuiError() YUILog::error ( YUILogComponent, __FILE__, __LINE__, __FUNCTION__ )
+
+
+class YUILogPrivate;
+
+enum YUILogLevel_t
+{
+ YUI_LOG_DEBUG = 0,
+ YUI_LOG_MILESTONE,
+ YUI_LOG_WARNING,
+ YUI_LOG_ERROR
+};
+
+
+/**
+ * UI logging.
+ **/
+class YUILog
+{
+public:
+
+ /**
+ * Logging functions for each log level. They all access the singleton object for this class.
+ * This means that the first call to any of those functions will create the singleton YUILog object.
+ **/
+ static std::ostream & debug ( const char * logComponent, const char * sourceFileName, int lineNo, const char * functionName );
+ static std::ostream & milestone( const char * logComponent, const char * sourceFileName, int lineNo, const char * functionName );
+ static std::ostream & warning ( const char * logComponent, const char * sourceFileName, int lineNo, const char * functionName );
+ static std::ostream & error ( const char * logComponent, const char * sourceFileName, int lineNo, const char * functionName );
+
+ /**
+ * Return the singleton object for this class.
+ * This will create the singleton if it doesn't exist yet.
+ **/
+ static YUILog * instance();
+
+ /**
+ * Enable or disable debug logging.
+ **/
+ static void enableDebugLogging( bool debugLogging = true );
+
+ /**
+ * Return 'true' if debug logging is enabled, 'false' if not.
+ **/
+ static bool debugLoggingEnabled();
+
+
+ typedef void (*YUILoggerFunction)( YUILogLevel_t, // logLevel
+ const char *, // logComponent
+ const char *, // sourceFileName
+ int // sourceLineNo
+ const char * // sourceFunctionName
+ const char * ); // message
+
+ /**
+ * Set the UI logger function. This is the function that will ultimately
+ * receive all UI log output (except debug logging if debug logging is
+ * disabled).
+ *
+ * By default, all logging is output to stdout. This behaviour can be
+ * restored if 0 is passed as a function pointer here.
+ **/
+ static void setLoggerFunction( YUILoggerFunction );
+
+ /**
+ * Return the UI logger function. 0 means stdout.
+ **/
+ static YUILoggerFunction loggerFunction();
+
+
+private:
+ /**
+ * Constructor.
+ *
+ * Not for application use - use one of the static functions above instead.
+ * They all access the singleton object for this class.
+ **/
+ YUILog();
+
+ /**
+ * Destructor.
+ **/
+ ~YUILog();
+
+ //
+ // Data
+ //
+
+ ImplPtr<YUILogPrivate> priv;
+};
+
+
+#define YUILog_h
+
+#endif // YUILog_h
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org