ctkDICOMUtil.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. dcmtk::log4cplus::Logger log = dcmtk::log4cplus::Logger::getRoot();
  24. switch (level)
  25. {
  26. case ctkErrorLogLevel::Trace: log.setLogLevel(OFLogger::TRACE_LOG_LEVEL); break;
  27. case ctkErrorLogLevel::Debug: log.setLogLevel(OFLogger::DEBUG_LOG_LEVEL); break;
  28. case ctkErrorLogLevel::Info: log.setLogLevel(OFLogger::INFO_LOG_LEVEL); break;
  29. case ctkErrorLogLevel::Warning: log.setLogLevel(OFLogger::WARN_LOG_LEVEL); break;
  30. case ctkErrorLogLevel::Error: log.setLogLevel(OFLogger::ERROR_LOG_LEVEL); break;
  31. case ctkErrorLogLevel::Fatal: log.setLogLevel(OFLogger::FATAL_LOG_LEVEL); break;
  32. default:
  33. qWarning() << "Failed to set DICOM log level - Supported levels are Trace, Debug, "
  34. "Info, Warning, Error and Fatal !";
  35. break;
  36. }
  37. }
  38. //------------------------------------------------------------------------------
  39. ctkErrorLogLevel::LogLevel ctk::dicomLogLevel()
  40. {
  41. dcmtk::log4cplus::Logger log = dcmtk::log4cplus::Logger::getRoot();
  42. switch (log.getLogLevel())
  43. {
  44. case OFLogger::TRACE_LOG_LEVEL: return ctkErrorLogLevel::Trace;
  45. case OFLogger::DEBUG_LOG_LEVEL: return ctkErrorLogLevel::Debug;
  46. case OFLogger::INFO_LOG_LEVEL: return ctkErrorLogLevel::Info;
  47. case OFLogger::WARN_LOG_LEVEL: return ctkErrorLogLevel::Warning;
  48. case OFLogger::ERROR_LOG_LEVEL: return ctkErrorLogLevel::Error;
  49. case OFLogger::FATAL_LOG_LEVEL: return ctkErrorLogLevel::Fatal;
  50. default: return ctkErrorLogLevel::None;
  51. }
  52. }
  53. //------------------------------------------------------------------------------
  54. QString ctk::dicomLogLevelAsString()
  55. {
  56. return ctkErrorLogLevel::logLevelAsString(ctk::dicomLogLevel());
  57. }