ctkLoggerTest1.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.commontk.org/LICENSE
  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 <QCoreApplication>
  16. // CTK includes
  17. #include <ctkLogger.h>
  18. // STL includes
  19. #include <cstdlib>
  20. #include <iostream>
  21. int ctkLoggerTest1(int argc, char * argv [] )
  22. {
  23. Q_UNUSED(argc);
  24. Q_UNUSED(argv);
  25. //--------------------------------------------------------------------
  26. ctkLogger logger("LoggerTest");
  27. std::cout<< "Logger default : " << logger.isOffEnabled() << std::endl;
  28. logger.setOff();
  29. if (!logger.isOffEnabled())
  30. {
  31. std::cerr << "Line " << __LINE__
  32. << " - Problem vith Logger::setOff()" << std::endl;
  33. return EXIT_FAILURE;
  34. }
  35. std::cout<< "Logger after setOff() : " << logger.isOffEnabled() << std::endl;
  36. //------------------------------------------------------------------
  37. std::cout<< "Logger Debug default : " << logger.isDebugEnabled() << std::endl;
  38. logger.setDebug();
  39. if (!logger.isDebugEnabled())
  40. {
  41. std::cerr << "Line " << __LINE__
  42. << " - Problem vith Logger::setDebug()" << std::endl;
  43. return EXIT_FAILURE;
  44. }
  45. std::cout << "Logger Debug after setDebug() : "
  46. << logger.isDebugEnabled() << std::endl;
  47. //------------------------------------------------------------------
  48. logger.setInfo();
  49. if (!logger.isInfoEnabled())
  50. {
  51. std::cerr << "Line " << __LINE__
  52. << " - Problem vith Logger::setDebug()" << std::endl;
  53. return EXIT_FAILURE;
  54. }
  55. //------------------------------------------------------------------
  56. logger.setTrace();
  57. if (!logger.isTraceEnabled())
  58. {
  59. std::cerr << "Line " << __LINE__
  60. << " - Problem vith Logger::setTrace()" << std::endl;
  61. return EXIT_FAILURE;
  62. }
  63. //------------------------------------------------------------------
  64. logger.setError();
  65. if (!logger.isErrorEnabled())
  66. {
  67. std::cerr << "Line " << __LINE__
  68. << " - Problem vith Logger::setError()" << std::endl;
  69. return EXIT_FAILURE;
  70. }
  71. //------------------------------------------------------------------
  72. logger.setWarn();
  73. if (!logger.isWarnEnabled())
  74. {
  75. std::cerr << "Line " << __LINE__
  76. << " - Problem vith Logger::setWarn()" << std::endl;
  77. return EXIT_FAILURE;
  78. }
  79. //------------------------------------------------------------------
  80. logger.setFatal();
  81. if (!logger.isFatalEnabled())
  82. {
  83. std::cerr << "Line " << __LINE__
  84. << " - Problem vith Logger::setFatal()" << std::endl;
  85. return EXIT_FAILURE;
  86. }
  87. //------------------------------------------------------------------
  88. logger.configure();
  89. QString defaultString;
  90. logger.debug(defaultString);
  91. logger.info(defaultString);
  92. logger.trace(defaultString);
  93. logger.warn(defaultString);
  94. logger.warn(defaultString);
  95. logger.error(defaultString);
  96. logger.fatal(defaultString);
  97. return EXIT_SUCCESS;
  98. }