LoggingLevel.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Copyright 2020 Canonical ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /*!
  15. * @file LoggingLevel.h
  16. */
  17. #ifndef _FASTDDS_RTPS_SECURITY_LOGGING_LOGGINGLEVEL_H_
  18. #define _FASTDDS_RTPS_SECURITY_LOGGING_LOGGINGLEVEL_H_
  19. #include <fastdds/rtps/security/exceptions/SecurityException.h>
  20. namespace eprosima {
  21. namespace fastrtps {
  22. namespace rtps {
  23. namespace security {
  24. /**
  25. * @brief The LoggingLevel enum
  26. *
  27. * @note Definition in DDS-Sec v1.1 9.6
  28. */
  29. enum struct LoggingLevel : long
  30. {
  31. EMERGENCY_LEVEL, // System is unusable. Should not continue use.
  32. ALERT_LEVEL, // Should be corrected immediately
  33. CRITICAL_LEVEL, // A failure in primary application.
  34. ERROR_LEVEL, // General error conditions
  35. WARNING_LEVEL, // May indicate future error if action not taken.
  36. NOTICE_LEVEL, // Unusual, but nor erroneous event or condition.
  37. INFORMATIONAL_LEVEL, // Normal operational. Requires no action.
  38. DEBUG_LEVEL
  39. };
  40. inline bool string_to_LogLevel(
  41. const std::string& s,
  42. LoggingLevel& l,
  43. SecurityException& e)
  44. {
  45. //TODO(artivis): use an array of const char to avoid strings?
  46. bool convert = true;
  47. if (!s.compare("0") || !s.compare("EMERGENCY_LEVEL"))
  48. {
  49. l = LoggingLevel::EMERGENCY_LEVEL;
  50. }
  51. else if (!s.compare("1") || !s.compare("ALERT_LEVEL"))
  52. {
  53. l = LoggingLevel::ALERT_LEVEL;
  54. }
  55. else if (!s.compare("2") || !s.compare("CRITICAL_LEVEL"))
  56. {
  57. l = LoggingLevel::CRITICAL_LEVEL;
  58. }
  59. else if (!s.compare("3") || !s.compare("ERROR_LEVEL"))
  60. {
  61. l = LoggingLevel::ERROR_LEVEL;
  62. }
  63. else if (!s.compare("4") || !s.compare("WARNING_LEVEL"))
  64. {
  65. l = LoggingLevel::WARNING_LEVEL;
  66. }
  67. else if (!s.compare("5") || !s.compare("NOTICE_LEVEL"))
  68. {
  69. l = LoggingLevel::NOTICE_LEVEL;
  70. }
  71. else if (!s.compare("6") || !s.compare("INFORMATIONAL_LEVEL"))
  72. {
  73. l = LoggingLevel::INFORMATIONAL_LEVEL;
  74. }
  75. else if (!s.compare("7") || !s.compare("DEBUG_LEVEL"))
  76. {
  77. l = LoggingLevel::DEBUG_LEVEL;
  78. }
  79. else
  80. {
  81. e = SecurityException("Unknown LoggingLevel");
  82. convert = false;
  83. }
  84. return convert;
  85. }
  86. inline bool LogLevel_to_string(
  87. const LoggingLevel l,
  88. std::string& s,
  89. SecurityException& e)
  90. {
  91. bool convert = true;
  92. switch (l)
  93. {
  94. case LoggingLevel::EMERGENCY_LEVEL:
  95. s = "EMERGENCY";
  96. break;
  97. case LoggingLevel::ALERT_LEVEL:
  98. s = "ALERT";
  99. break;
  100. case LoggingLevel::CRITICAL_LEVEL:
  101. s = "CRITICAL";
  102. break;
  103. case LoggingLevel::ERROR_LEVEL:
  104. s = "ERROR";
  105. break;
  106. case LoggingLevel::WARNING_LEVEL:
  107. s = "WARNING";
  108. break;
  109. case LoggingLevel::NOTICE_LEVEL:
  110. s = "NOTICE";
  111. break;
  112. case LoggingLevel::INFORMATIONAL_LEVEL:
  113. s = "INFORMATIONAL";
  114. break;
  115. case LoggingLevel::DEBUG_LEVEL:
  116. s = "DEBUG";
  117. break;
  118. default:
  119. s = "UNKNOWN";
  120. convert = false;
  121. e = SecurityException("Unknown LoggingLevel");
  122. break;
  123. }
  124. return convert;
  125. }
  126. } //namespace security
  127. } //namespace rtps
  128. } //namespace fastrtps
  129. } //namespace eprosima
  130. #endif // _FASTDDS_RTPS_SECURITY_LOGGING_LOGGINGLEVEL_H_