1
0

log.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /** @file log.c
  2. * @brief Helpers for logging
  3. */
  4. #ifdef HAVE_CONFIG_H
  5. #include "config.h"
  6. #endif /* HAVE_CONFIG_H */
  7. #include <syslog.h>
  8. #include "faux/str.h"
  9. #include "faux/log.h"
  10. /** @brief Parses syslog facility string and returns the facility id.
  11. *
  12. * Gets syslog facility string, parse it and finds out the facility
  13. * id in digital form. Usefull config or command line options parsing.
  14. *
  15. * @param [in] str Facility string.
  16. * @param [out] facility Facility in digital form.
  17. * @returns 0 - success, < 0 - parsing error
  18. */
  19. int faux_log_facility(const char *str, int *facility) {
  20. if (!faux_str_casecmp(str, "local0"))
  21. *facility = LOG_LOCAL0;
  22. else if (!faux_str_casecmp(str, "local1"))
  23. *facility = LOG_LOCAL1;
  24. else if (!faux_str_casecmp(str, "local2"))
  25. *facility = LOG_LOCAL2;
  26. else if (!faux_str_casecmp(str, "local3"))
  27. *facility = LOG_LOCAL3;
  28. else if (!faux_str_casecmp(str, "local4"))
  29. *facility = LOG_LOCAL4;
  30. else if (!faux_str_casecmp(str, "local5"))
  31. *facility = LOG_LOCAL5;
  32. else if (!faux_str_casecmp(str, "local6"))
  33. *facility = LOG_LOCAL6;
  34. else if (!faux_str_casecmp(str, "local7"))
  35. *facility = LOG_LOCAL7;
  36. else if (!faux_str_casecmp(str, "auth"))
  37. *facility = LOG_AUTH;
  38. #ifdef LOG_AUTHPRIV
  39. else if (!faux_str_casecmp(str, "authpriv"))
  40. *facility = LOG_AUTHPRIV;
  41. #endif
  42. else if (!faux_str_casecmp(str, "cron"))
  43. *facility = LOG_CRON;
  44. else if (!faux_str_casecmp(str, "daemon"))
  45. *facility = LOG_DAEMON;
  46. #ifdef LOG_FTP
  47. else if (!faux_str_casecmp(str, "ftp"))
  48. *facility = LOG_FTP;
  49. #endif
  50. else if (!faux_str_casecmp(str, "kern"))
  51. *facility = LOG_KERN;
  52. else if (!faux_str_casecmp(str, "lpr"))
  53. *facility = LOG_LPR;
  54. else if (!faux_str_casecmp(str, "mail"))
  55. *facility = LOG_MAIL;
  56. else if (!faux_str_casecmp(str, "news"))
  57. *facility = LOG_NEWS;
  58. else if (!faux_str_casecmp(str, "syslog"))
  59. *facility = LOG_SYSLOG;
  60. else if (!faux_str_casecmp(str, "user"))
  61. *facility = LOG_USER;
  62. else if (!faux_str_casecmp(str, "uucp"))
  63. *facility = LOG_UUCP;
  64. else
  65. return -1;
  66. return 0;
  67. }