priority.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. static const char version[] = "$Id$";
  2. /*
  3. * priority.c
  4. *
  5. * Copyright 2001-2003, Meiosys (www.meiosys.com). All rights reserved.
  6. *
  7. * See the COPYING file for the terms of usage and distribution.
  8. */
  9. #include <string.h>
  10. #include <log4c/priority.h>
  11. #include <sd/sd_xplatform.h>
  12. static const char* const priorities[] = {
  13. "FATAL",
  14. "ALERT",
  15. "CRIT",
  16. "ERROR",
  17. "WARN",
  18. "NOTICE",
  19. "INFO",
  20. "DEBUG",
  21. "TRACE",
  22. "NOTSET",
  23. "UNKNOWN"
  24. };
  25. static const size_t npriorities = sizeof(priorities) / sizeof(priorities[0]);
  26. /*******************************************************************************/
  27. extern const char* log4c_priority_to_string(int a_priority)
  28. {
  29. a_priority /= 100;
  30. if ( (a_priority < 0) || (a_priority > 10) )
  31. a_priority = 10;
  32. return priorities[a_priority];
  33. }
  34. /*******************************************************************************/
  35. extern int log4c_priority_to_int(const char* a_priority_name)
  36. {
  37. size_t i;
  38. if (a_priority_name) {
  39. for (i = 0; i < npriorities; i++) {
  40. if (!strncasecmp(priorities[i], a_priority_name, strlen(priorities[i])))
  41. return i * 100;
  42. }
  43. }
  44. return LOG4C_PRIORITY_UNKNOWN;
  45. }