You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.5 KiB

  1. // Module: Log4cplus
  2. // File: qt4debugappender.cxx
  3. // Created: 6/2012
  4. // Author: Vaclav Zeman
  5. //
  6. //
  7. // Copyright (C) 2012, Vaclav Zeman. All rights reserved.
  8. //
  9. // Redistribution and use in source and binary forms, with or without modifica-
  10. // tion, are permitted provided that the following conditions are met:
  11. //
  12. // 1. Redistributions of source code must retain the above copyright notice,
  13. // this list of conditions and the following disclaimer.
  14. //
  15. // 2. Redistributions in binary form must reproduce the above copyright notice,
  16. // this list of conditions and the following disclaimer in the documentation
  17. // and/or other materials provided with the distribution.
  18. //
  19. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  20. // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  21. // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  22. // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  23. // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  24. // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  25. // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28. // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. #include <log4cplus/config.hxx>
  30. #include <log4cplus/qt4debugappender.h>
  31. #include <log4cplus/helpers/loglog.h>
  32. #include <log4cplus/helpers/property.h>
  33. #include <log4cplus/spi/factory.h>
  34. #include <log4cplus/spi/loggingevent.h>
  35. #include <sstream>
  36. #include <iomanip>
  37. #include <QtGlobal>
  38. #include <log4cplus/config/windowsh-inc.h>
  39. // Forward Declarations
  40. namespace log4cplus
  41. {
  42. Qt4DebugAppender::Qt4DebugAppender ()
  43. : Appender ()
  44. { }
  45. Qt4DebugAppender::Qt4DebugAppender (helpers::Properties const & props)
  46. : Appender (props)
  47. { }
  48. Qt4DebugAppender::~Qt4DebugAppender ()
  49. {
  50. destructorImpl ();
  51. }
  52. void
  53. Qt4DebugAppender::close ()
  54. { }
  55. void
  56. Qt4DebugAppender::append (spi::InternalLoggingEvent const & ev)
  57. {
  58. // TODO: Expose log4cplus' internal TLS to use here.
  59. tostringstream oss;
  60. layout->formatAndAppend(oss, ev);
  61. LogLevel const ll = ev.getLogLevel ();
  62. void (* log_func) (const char *, ...) = 0;
  63. if (ll >= ERROR_LOG_LEVEL)
  64. log_func = qCritical;
  65. else if (ll >= WARN_LOG_LEVEL)
  66. log_func = qWarning;
  67. else
  68. log_func = qDebug;
  69. log_func ("%s", LOG4CPLUS_TSTRING_TO_STRING (oss.str ()).c_str ());
  70. }
  71. void
  72. Qt4DebugAppender::registerAppender ()
  73. {
  74. log4cplus::spi::AppenderFactoryRegistry & reg
  75. = log4cplus::spi::getAppenderFactoryRegistry ();
  76. LOG4CPLUS_REG_APPENDER (reg, Qt4DebugAppender);
  77. }
  78. } // namespace log4cplus
  79. #if defined (_WIN32)
  80. extern "C"
  81. BOOL WINAPI DllMain(LOG4CPLUS_DLLMAIN_HINSTANCE, // handle to DLL module
  82. DWORD fdwReason, // reason for calling function
  83. LPVOID) // reserved
  84. {
  85. // Perform actions based on the reason for calling.
  86. switch( fdwReason )
  87. {
  88. case DLL_PROCESS_ATTACH:
  89. {
  90. log4cplus::Qt4DebugAppender::registerAppender ();
  91. break;
  92. }
  93. case DLL_THREAD_ATTACH:
  94. break;
  95. case DLL_THREAD_DETACH:
  96. break;
  97. case DLL_PROCESS_DETACH:
  98. break;
  99. }
  100. return TRUE; // Successful DLL_PROCESS_ATTACH.
  101. }
  102. #endif // defined (_WIN32)