log.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "lub/log.h"
  2. #include <syslog.h>
  3. #include "lub/string.h"
  4. int lub_log_facility(const char *str, int *facility)
  5. {
  6. if (!lub_string_nocasecmp(str, "local0"))
  7. *facility = LOG_LOCAL0;
  8. else if (!lub_string_nocasecmp(str, "local1"))
  9. *facility = LOG_LOCAL1;
  10. else if (!lub_string_nocasecmp(str, "local2"))
  11. *facility = LOG_LOCAL2;
  12. else if (!lub_string_nocasecmp(str, "local3"))
  13. *facility = LOG_LOCAL3;
  14. else if (!lub_string_nocasecmp(str, "local4"))
  15. *facility = LOG_LOCAL4;
  16. else if (!lub_string_nocasecmp(str, "local5"))
  17. *facility = LOG_LOCAL5;
  18. else if (!lub_string_nocasecmp(str, "local6"))
  19. *facility = LOG_LOCAL6;
  20. else if (!lub_string_nocasecmp(str, "local7"))
  21. *facility = LOG_LOCAL7;
  22. else if (!lub_string_nocasecmp(str, "auth"))
  23. *facility = LOG_AUTH;
  24. #ifdef LOG_AUTHPRIV
  25. else if (!lub_string_nocasecmp(str, "authpriv"))
  26. *facility = LOG_AUTHPRIV;
  27. #endif
  28. else if (!lub_string_nocasecmp(str, "cron"))
  29. *facility = LOG_CRON;
  30. else if (!lub_string_nocasecmp(str, "daemon"))
  31. *facility = LOG_DAEMON;
  32. #ifdef LOG_FTP
  33. else if (!lub_string_nocasecmp(str, "ftp"))
  34. *facility = LOG_FTP;
  35. #endif
  36. else if (!lub_string_nocasecmp(str, "kern"))
  37. *facility = LOG_KERN;
  38. else if (!lub_string_nocasecmp(str, "lpr"))
  39. *facility = LOG_LPR;
  40. else if (!lub_string_nocasecmp(str, "mail"))
  41. *facility = LOG_MAIL;
  42. else if (!lub_string_nocasecmp(str, "news"))
  43. *facility = LOG_NEWS;
  44. else if (!lub_string_nocasecmp(str, "syslog"))
  45. *facility = LOG_SYSLOG;
  46. else if (!lub_string_nocasecmp(str, "user"))
  47. *facility = LOG_USER;
  48. else if (!lub_string_nocasecmp(str, "uucp"))
  49. *facility = LOG_UUCP;
  50. else
  51. return -1;
  52. return 0;
  53. }