ctkLogger.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QDebug>
  16. #include <QSqlDatabase>
  17. // CTK includes
  18. #include <ctkLogger.h>
  19. // Log4Qt includes
  20. #include <log4qt/log4qt.h>
  21. #include <log4qt/logger.h>
  22. #include <log4qt/basicconfigurator.h>
  23. //-----------------------------------------------------------------------------
  24. class ctkLoggerPrivate
  25. {
  26. public:
  27. Log4Qt::Logger *Logger;
  28. };
  29. //-----------------------------------------------------------------------------
  30. ctkLogger::ctkLogger(QString name, QObject* _parent)
  31. : Superclass(_parent)
  32. , d_ptr(new ctkLoggerPrivate)
  33. {
  34. Q_D(ctkLogger);
  35. d->Logger = Log4Qt::Logger::logger( name.toStdString().c_str());
  36. }
  37. //-----------------------------------------------------------------------------
  38. ctkLogger::~ctkLogger()
  39. {
  40. }
  41. //-----------------------------------------------------------------------------
  42. void ctkLogger::configure()
  43. {
  44. Log4Qt::BasicConfigurator::configure();
  45. }
  46. //-----------------------------------------------------------------------------
  47. void ctkLogger::debug(const QString& s)
  48. {
  49. Q_D(ctkLogger);
  50. d->Logger->debug(s);
  51. }
  52. //-----------------------------------------------------------------------------
  53. void ctkLogger::info(const QString& s)
  54. {
  55. Q_D(ctkLogger);
  56. d->Logger->info(s);
  57. }
  58. //-----------------------------------------------------------------------------
  59. void ctkLogger::trace(const QString& s)
  60. {
  61. Q_D(ctkLogger);
  62. d->Logger->trace(s);
  63. }
  64. //-----------------------------------------------------------------------------
  65. void ctkLogger::warn(const QString& s)
  66. {
  67. Q_D(ctkLogger);
  68. d->Logger->warn(s);
  69. }
  70. //-----------------------------------------------------------------------------
  71. void ctkLogger::error(const QString& s)
  72. {
  73. Q_D(ctkLogger);
  74. d->Logger->error(s);
  75. }
  76. //-----------------------------------------------------------------------------
  77. void ctkLogger::fatal(const QString& s)
  78. {
  79. Q_D(ctkLogger);
  80. d->Logger->fatal(s);
  81. }
  82. //-----------------------------------------------------------------------------
  83. void ctkLogger::setOff()
  84. {
  85. Q_D(ctkLogger);
  86. d->Logger->setLevel(Log4Qt::Level(Log4Qt::Level::OFF_INT));
  87. }
  88. //-----------------------------------------------------------------------------
  89. void ctkLogger::setDebug()
  90. {
  91. Q_D(ctkLogger);
  92. d->Logger->setLevel(Log4Qt::Level(Log4Qt::Level::DEBUG_INT));
  93. }
  94. //-----------------------------------------------------------------------------
  95. void ctkLogger::setInfo()
  96. {
  97. Q_D(ctkLogger);
  98. d->Logger->setLevel(Log4Qt::Level(Log4Qt::Level::INFO_INT));
  99. }
  100. //-----------------------------------------------------------------------------
  101. void ctkLogger::setTrace()
  102. {
  103. Q_D(ctkLogger);
  104. d->Logger->setLevel(Log4Qt::Level(Log4Qt::Level::TRACE_INT));
  105. }
  106. //-----------------------------------------------------------------------------
  107. void ctkLogger::setWarn()
  108. {
  109. Q_D(ctkLogger);
  110. d->Logger->setLevel(Log4Qt::Level(Log4Qt::Level::WARN_INT));
  111. }
  112. //-----------------------------------------------------------------------------
  113. void ctkLogger::setError()
  114. {
  115. Q_D(ctkLogger);
  116. d->Logger->setLevel(Log4Qt::Level(Log4Qt::Level::ERROR_INT));
  117. }
  118. //-----------------------------------------------------------------------------
  119. void ctkLogger::setFatal()
  120. {
  121. Q_D(ctkLogger);
  122. d->Logger->setLevel(Log4Qt::Level(Log4Qt::Level::FATAL_INT));
  123. }
  124. //-----------------------------------------------------------------------------
  125. bool ctkLogger::isOffEnabled()
  126. {
  127. Q_D(ctkLogger); //Not sure
  128. return d->Logger->isEnabledFor(Log4Qt::Level(Log4Qt::Level::OFF_INT));
  129. }
  130. //-----------------------------------------------------------------------------
  131. bool ctkLogger::isDebugEnabled()
  132. {
  133. Q_D(ctkLogger);
  134. return d->Logger->isDebugEnabled();
  135. }
  136. //-----------------------------------------------------------------------------
  137. bool ctkLogger::isInfoEnabled()
  138. {
  139. Q_D(ctkLogger);
  140. return d->Logger->isInfoEnabled();
  141. }
  142. //-----------------------------------------------------------------------------
  143. bool ctkLogger::isTraceEnabled()
  144. {
  145. Q_D(ctkLogger);
  146. return d->Logger->isTraceEnabled();
  147. }
  148. //-----------------------------------------------------------------------------
  149. bool ctkLogger::isWarnEnabled()
  150. {
  151. Q_D(ctkLogger);
  152. return d->Logger->isWarnEnabled();
  153. }
  154. //-----------------------------------------------------------------------------
  155. bool ctkLogger::isErrorEnabled()
  156. {
  157. Q_D(ctkLogger);
  158. return d->Logger->isErrorEnabled();
  159. }
  160. //-----------------------------------------------------------------------------
  161. bool ctkLogger::isFatalEnabled()
  162. {
  163. Q_D(ctkLogger);
  164. return d->Logger->isFatalEnabled();
  165. }