priority.c 1.2 KB

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