basicconfigurator.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /******************************************************************************
  2. *
  3. * package: Log4Qt
  4. * file: basicconfigurator.cpp
  5. * created: September 2007
  6. * author: Martin Heinrich
  7. *
  8. *
  9. * Copyright 2007 Martin Heinrich
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. *
  23. ******************************************************************************/
  24. /******************************************************************************
  25. * Dependencies
  26. ******************************************************************************/
  27. #include "log4qt/basicconfigurator.h"
  28. #include <QtCore/QCoreApplication>
  29. #include <QtCore/QDebug>
  30. #include <QtCore/QThread>
  31. #include "log4qt/consoleappender.h"
  32. #include "log4qt/helpers/configuratorhelper.h"
  33. #include "log4qt/helpers/logobjectptr.h"
  34. #include "log4qt/logmanager.h"
  35. #include "log4qt/patternlayout.h"
  36. #include "log4qt/varia/listappender.h"
  37. namespace Log4Qt
  38. {
  39. /**************************************************************************
  40. * Declarations
  41. **************************************************************************/
  42. /**************************************************************************
  43. * C helper functions
  44. **************************************************************************/
  45. /**************************************************************************
  46. * Class implementation: BasicConfigurator
  47. **************************************************************************/
  48. bool BasicConfigurator::configure()
  49. {
  50. LogObjectPtr<ListAppender> list = new ListAppender;
  51. list->setName(QLatin1String("BasicConfigurator"));
  52. list->setConfiguratorList(true);
  53. list->setThreshold(Level::ERROR_INT);
  54. LogManager::logLogger()->addAppender(list);
  55. PatternLayout *p_layout = new PatternLayout(PatternLayout::TTCC_CONVERSION_PATTERN);
  56. p_layout->setName(QLatin1String("BasicConfigurator TTCC"));
  57. p_layout->activateOptions();
  58. ConsoleAppender *p_appender = new ConsoleAppender(p_layout, ConsoleAppender::STDOUT_TARGET);
  59. p_appender->setName(QLatin1String("BasicConfigurator stdout"));
  60. p_appender->activateOptions();
  61. LogManager::rootLogger()->addAppender(p_appender);
  62. LogManager::logLogger()->removeAppender(list);
  63. ConfiguratorHelper::setConfigureError(list->list());
  64. return (list->list().count() == 0);
  65. }
  66. void BasicConfigurator::configure(Appender *pAppender)
  67. {
  68. LogManager::rootLogger()->addAppender(pAppender);
  69. }
  70. void BasicConfigurator::resetConfiguration()
  71. {
  72. LogManager::resetConfiguration();
  73. }
  74. /**************************************************************************
  75. * Implementation: Operators, Helper
  76. **************************************************************************/
  77. } // namespace Log4Qt