Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "PortabilityImpl.hh"
00011 #include <log4cpp/Priority.hh>
00012 #include <cstdlib>
00013
00014 namespace log4cpp {
00015
00016 namespace {
00017 const std::string names[10] = {
00018 "FATAL",
00019 "ALERT",
00020 "CRIT",
00021 "ERROR",
00022 "WARN",
00023 "NOTICE",
00024 "INFO",
00025 "DEBUG",
00026 "NOTSET",
00027 "UNKNOWN"
00028 };
00029 }
00030
00031 const int log4cpp::Priority::MESSAGE_SIZE = 8;
00032
00033
00034 const std::string& Priority::getPriorityName(int priority) throw() {
00035
00036 priority++;
00037 priority /= 100;
00038 return names[((priority < 0) || (priority > 8)) ? 8 : priority];
00039 }
00040
00041 Priority::Value Priority::getPriorityValue(const std::string& priorityName)
00042 throw(std::invalid_argument) {
00043 Priority::Value value = -1;
00044
00045 for (unsigned int i = 0; i < 10; i++) {
00046 if (priorityName == names[i]) {
00047 value = i * 100;
00048 break;
00049 }
00050 }
00051
00052 if (value == -1) {
00053 if (priorityName == "EMERG") {
00054 value = 0;
00055 } else {
00056 char* endPointer;
00057 value = std::strtoul(priorityName.c_str(), &endPointer, 10);
00058 if (*endPointer != 0) {
00059 throw std::invalid_argument(
00060 std::string("unknown priority name: '") + priorityName + "'"
00061 );
00062 }
00063 }
00064 }
00065
00066 return value;
00067 }
00068 }