qt_listener.cpp

Go to the documentation of this file.
00001 
00008 /**************************************************************************
00009 
00010    begin                : Sun Oct 30 2007
00011    copyright            : (C) 2007 by Ewald Arnold
00012    email                : log4sendpp at ewald-arnold dot de
00013 
00014    This program is free software; you can redistribute it and/or modify
00015    it under the terms of the GNU Lesser General Public License as
00016    published by the Free Software Foundation; either version 2 of the License,
00017    or (at your option) any later version.
00018 
00019    This program is distributed in the hope that it will be useful,
00020    but WITHOUT ANY WARRANTY; without even the implied warranty of
00021    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022    GNU General Public License for more details.
00023 
00024    You should have received a copy of the GNU Lesser General Public License
00025    along with this program; if not, write to the Free Software
00026    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00027 
00028  **/
00029 
00031 #define LOG4SENDPP_NEED_EXPORTS
00032 #include <log4sendpp/log4sendpp.h> // always first
00033 
00034 #ifdef LOG4SENDPP_USE_QT
00035 
00036 #include <log4sendpp/arguments.h>
00037 #include <log4sendpp/locationinfo.h>
00038 #include <log4sendpp/qt_listener.h>
00039 
00040 
00041 LOG4SENDPP_NS_START
00042 
00043 
00044 LOG4SENDPP_API_IMPL0 QtListener::QtListener()
00045 {
00046   oldMessageHandler = qInstallMsgHandler( &QtListener::messageHandler );
00047 }
00048 
00049 
00050 LOG4SENDPP_API_IMPL0 QtListener::~QtListener()
00051 {
00052   qInstallMsgHandler( oldMessageHandler  );
00053 }
00054 
00055 
00056 LOG4SENDPP_API_IMPL(void) QtListener::messageHandler(QtMsgType type, const char *msg)
00057 {
00058   LOG4SENDPP_NS::LocationInformation loc("",
00059                                          0, //
00060                                          "",
00061                                          LOG4SENDPP_NS::ThreadDictionary::getCurrentNickname(),
00062                                          "");
00063   Logger::Level level = Logger::Error;
00064   switch (type)
00065   {
00066     case QtDebugMsg:
00067       level = Logger::Debug;
00068     break;
00069 
00070     case QtWarningMsg:
00071       level = Logger::Warning;
00072     break;
00073 
00074     case QtFatalMsg:
00075       level = Logger::Fatal;
00076     break;
00077 
00078     default:
00079       level = Logger::Error;
00080   }
00081 
00082   LOG4SENDPP_NS::Logger::logger().log(level, msg, "Qt", &loc);
00083 }
00084 
00085 
00086 LOG4SENDPP_NS_END
00087 
00088 
00089 #endif // LOG4SENDPP_USE_QT
00090 

Generated on Sat Nov 24 14:41:22 2007 for log4sendpp by  doxygen 1.5.3