ctkDICOMUtil.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Brigham & Women's Hospital
  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. // CTK includes
  17. #include "ctkDICOMUtil.h"
  18. // DCMTK includes
  19. #include <dcmtk/oflog/oflog.h>
  20. //------------------------------------------------------------------------------
  21. void ctk::setDICOMLogLevel(ctkErrorLogLevel::LogLevel level)
  22. {
  23. #ifdef HAVE_DCMTK_LOG4CPLUS_LOGGER
  24. dcmtk::log4cplus::Logger log = dcmtk::log4cplus::Logger::getRoot();
  25. #else
  26. log4cplus::Logger log = log4cplus::Logger::getRoot();
  27. #endif
  28. switch (level)
  29. {
  30. case ctkErrorLogLevel::Trace: log.setLogLevel(OFLogger::TRACE_LOG_LEVEL); break;
  31. case ctkErrorLogLevel::Debug: log.setLogLevel(OFLogger::DEBUG_LOG_LEVEL); break;
  32. case ctkErrorLogLevel::Info: log.setLogLevel(OFLogger::INFO_LOG_LEVEL); break;
  33. case ctkErrorLogLevel::Warning: log.setLogLevel(OFLogger::WARN_LOG_LEVEL); break;
  34. case ctkErrorLogLevel::Error: log.setLogLevel(OFLogger::ERROR_LOG_LEVEL); break;
  35. case ctkErrorLogLevel::Fatal: log.setLogLevel(OFLogger::FATAL_LOG_LEVEL); break;
  36. default:
  37. qWarning() << "Failed to set DICOM log level - Supported levels are Trace, Debug, "
  38. "Info, Warning, Error and Fatal !";
  39. break;
  40. }
  41. }
  42. //------------------------------------------------------------------------------
  43. ctkErrorLogLevel::LogLevel ctk::dicomLogLevel()
  44. {
  45. #ifdef HAVE_DCMTK_LOG4CPLUS_LOGGER
  46. dcmtk::log4cplus::Logger log = dcmtk::log4cplus::Logger::getRoot();
  47. #else
  48. log4cplus::Logger log = log4cplus::Logger::getRoot();
  49. #endif
  50. switch (log.getLogLevel())
  51. {
  52. case OFLogger::TRACE_LOG_LEVEL: return ctkErrorLogLevel::Trace;
  53. case OFLogger::DEBUG_LOG_LEVEL: return ctkErrorLogLevel::Debug;
  54. case OFLogger::INFO_LOG_LEVEL: return ctkErrorLogLevel::Info;
  55. case OFLogger::WARN_LOG_LEVEL: return ctkErrorLogLevel::Warning;
  56. case OFLogger::ERROR_LOG_LEVEL: return ctkErrorLogLevel::Error;
  57. case OFLogger::FATAL_LOG_LEVEL: return ctkErrorLogLevel::Fatal;
  58. default: return ctkErrorLogLevel::None;
  59. }
  60. }
  61. //------------------------------------------------------------------------------
  62. QString ctk::dicomLogLevelAsString()
  63. {
  64. return ctkErrorLogLevel::logLevelAsString(ctk::dicomLogLevel());
  65. }