DumontEXE 0.0.1
QxtLogger.h
00001 /* ***************************************************************************
00002 **
00003 ** Copyright (C) 2007 Lorimark Solutions, LLC. All rights reserved.
00004 **
00005 ** This file is part of the DumontEXE Scripting Extension Kit
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://dumont.showoff-db.org/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://dumont.showoff-db.org/licensing.html 
00017 ** or contact the sales department at sales@lorimarksolutions.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ** author: Mark Petryk ~ Lorimark Solutions, LLC
00023 ** **************************************************************************/
00024 
00025 #ifndef QXTLOGGER_H_47494031_6360_4d74_B029_57FE6E69222C
00026 #define QXTLOGGER_H_47494031_6360_4d74_B029_57FE6E69222C
00027 
00028 #include <QPointer>
00029 #include <QDockWidget>
00030 #include <QTextEdit>
00031 
00032 class QxtLogger;
00033 class QTextEdit;
00034 
00035 /*!
00036 ** \brief Logger Window
00037 **
00038 ** This is a Logger window for vbScript.  This is one darned handy thing for
00039 **  for a vbScript application.  Rather than having to rely on a series of
00040 **  msgBox() statements in your code to find out what's going on in your code,
00041 **  you can place a series of logging statements, and actually watch what's
00042 **  happening while the application is running.
00043 **
00044 ** This object is invoked from the DumontEXE::logWindow interface.
00045 **
00046 */
00047 class QxtLoggerWindow
00048 :
00049   public  QTextEdit
00050 {
00051   Q_OBJECT
00052   public:
00053 
00054     /*!
00055     ** \brief Default Constructor <br>
00056     **
00057     **
00058     */
00059     QxtLoggerWindow
00060     (
00061       const QString & name,
00062       QWidget * parent,
00063       int x = -1,
00064       int y = -1,
00065       int w = -1,
00066       int h = -1
00067     );
00068 
00069     ~QxtLoggerWindow();
00070 
00071     void savePosition();
00072 
00073   public slots:
00074 
00075     /*!
00076     ** \brief Print to the Log Window
00077     **
00078     **
00079     */
00080     void print
00081     (
00082       /*! String (optional) ~ line to be sent to the log window */
00083       const QString & line = ""
00084     );
00085 
00086     void print( const long value )   { print( QString::number(value)         ); }
00087     void print( const double value ) { print( QString::number(value)         ); }
00088     void print( const bool value )   { print( QString(value? "True":"False") ); }
00089 
00090     /*!
00091     ** \brief Over Print to the Log Window
00092     **
00093     **
00094     */
00095     void oprint
00096     (
00097       /*! String (optional) ~ line to be sent to the log window */
00098       const QString & line = ""
00099     );
00100 
00101     void oprint( const long value )   { oprint( QString::number(value)         ); }
00102     void oprint( const double value ) { oprint( QString::number(value)         ); }
00103     void oprint( const bool value )   { oprint( QString(value? "True":"False") ); }
00104 
00105 
00106 
00107     /*!
00108     ** \brief Save the log to a text file <br>
00109     **
00110     ** \return boolean ~ False if file could not be saved
00111     */
00112     bool save
00113     (
00114       /*! String ~ Path and Filename to save to - the path must exist and be
00115       **   a writable directory
00116       */
00117       const QString & filename
00118     );
00119 
00120   private:
00121 
00122 }; // endclass QxtLoggerWindow
00123 
00124 
00125 class QxtLoggerManager
00126 :
00127   public QObject
00128 {
00129   Q_OBJECT
00130   public:
00131 
00132     QxtLoggerManager( QObject * parent = NULL );
00133     virtual ~QxtLoggerManager();
00134 
00135     void init(void);
00136 
00137     static QxtLoggerManager * instance(void);
00138 
00139   public slots:
00140 
00141     QxtLogger * getRootLogger(void);
00142     QxtLogger * getLogger( const QString & name );
00143 
00144   signals:
00145 
00146   protected:
00147 
00148   private:
00149 
00150     /*!
00151     ** \brief Qt message trap
00152     **
00153     ** This function traps messages sent by qDebug, qWarning, qCritical, qFatal
00154     **  and processes them through the logging engine.  It is static and private
00155     **  because nothing should have access to it besides the logger.
00156     **
00157     */
00158     static void messageTrap( QtMsgType type, const char *msg );
00159 
00160     static QxtLoggerManager * s_self;
00161     QPointer<QxtLogger> m_rootLogger;
00162 
00163 }; // endclass QxtLoggerManager
00164 
00165 #define qxtLoggerManager QxtLoggerManager::instance()
00166 
00167 /*!
00168 ** \brief Log Manager
00169 **
00170 ** Only one log manager is allowed to exist in the system.
00171 **
00172 */
00173 class QxtLogger
00174 : 
00175   public QObject
00176 {
00177   Q_OBJECT
00178   public:
00179 
00180     enum Level { Null, Trace, Debug, Info, Warning, Critical, Fatal };
00181 
00182     QxtLogger( const QString & name, QxtLogger * parent = NULL );
00183 
00184     virtual ~QxtLogger();
00185 
00186   public slots:
00187 
00188     virtual void trace( const QString & msg );
00189     virtual void debug( const QString & msg );
00190     virtual void info( const QString & msg );
00191     virtual void warning( const QString & msg );
00192     virtual void critical( const QString & msg );
00193     virtual void fatal( const QString & msg );
00194     virtual void log( const Level l, const QString & msg );
00195     virtual void clear();
00196 
00197     virtual QxtLogger * parent(void);
00198 
00199   protected:
00200 
00201   private:
00202 
00203     QPointer<QTextEdit> m_text;
00204 
00205 }; // endclass QxtLogger
00206 
00207 
00208 
00209 #endif // #ifndef QXTLOGGER_H
00210 
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties




~ ~ ~ ~ ~ ~
Source Code without Comments is like a Cranberry Garland
without the berries. Comment your Code!
 
Commence Database User Support Group Forum
http://newsgroup.showoff-db.org/
~ ~ ~ ~ ~ ~
Author: Mark Petryk
Lorimark Solutions, LLC
mark@lorimarksolutions.com