log.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Gearman server and library
  2. * Copyright (C) 2008 Brian Aker, Eric Day
  3. * All rights reserved.
  4. *
  5. * Use and distribution licensed under the BSD license. See
  6. * the COPYING file in the parent directory for full text.
  7. */
  8. /*
  9. All logging facilities within the server.
  10. */
  11. #include <stdio.h>
  12. #pragma once
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #define STRINGIFY(x) #x
  17. #define TOSTRING(x) STRINGIFY(x)
  18. #define AT __FILE__ ":" TOSTRING(__LINE__)
  19. #ifdef __cplusplus
  20. #define gearman_literal_param(X) (X), (size_t(sizeof(X) - 1))
  21. #else
  22. #define gearman_literal_param(X) (X), ((size_t)((sizeof(X) - 1)))
  23. #endif
  24. #define GEARMAN_DEFAULT_LOG_PARAM AT, __func__
  25. GEARMAN_INTERNAL_API
  26. void gearmand_initialize_thread_logging(const char *identity);
  27. /**
  28. * Log a fatal message, see gearmand_log() for argument details.
  29. */
  30. GEARMAN_INTERNAL_API
  31. void gearmand_log_fatal(const char *position, const char *func, const char *format, ...);
  32. #define gearmand_fatal(_mesg) gearmand_log_fatal(GEARMAN_DEFAULT_LOG_PARAM, (_mesg))
  33. GEARMAN_INTERNAL_API
  34. void gearmand_log_fatal_perror(const char *position, const char *function, const char *message);
  35. #define gearmand_fatal_perror(_mesg) gearmand_log_fatal_perror(GEARMAN_DEFAULT_LOG_PARAM, (_mesg))
  36. /**
  37. * Log an error message, see gearmand_log() for argument details.
  38. */
  39. GEARMAN_INTERNAL_API
  40. gearmand_error_t gearmand_log_error(const char *position, const char *function, const char *format, ...);
  41. #define gearmand_error(_mesg) gearmand_log_error(GEARMAN_DEFAULT_LOG_PARAM, (_mesg))
  42. GEARMAN_INTERNAL_API
  43. gearmand_error_t gearmand_log_perror(const char *position, const char *function, const char *message);
  44. #define gearmand_perror(_mesg) gearmand_log_perror(GEARMAN_DEFAULT_LOG_PARAM, (_mesg))
  45. GEARMAN_INTERNAL_API
  46. gearmand_error_t gearmand_log_gerror(const char *position, const char *function, const gearmand_error_t rc, const char *format, ...);
  47. #define gearmand_gerror(_mesg, _gearmand_errot_t) gearmand_log_gerror(GEARMAN_DEFAULT_LOG_PARAM, (_gearmand_errot_t), (_mesg))
  48. GEARMAN_INTERNAL_API
  49. gearmand_error_t gearmand_log_gerror_warn(const char *position, const char *function, const gearmand_error_t rc, const char *format, ...);
  50. #define gearmand_gerror_warn(_mesg, _gearmand_errot_t) gearmand_log_gerror_warn(GEARMAN_DEFAULT_LOG_PARAM, (_gearmand_errot_t), (_mesg))
  51. GEARMAN_INTERNAL_API
  52. gearmand_error_t gearmand_log_gai_error(const char *position, const char *function, const int rc, const char *message);
  53. #define gearmand_gai_error(_mesg, _gai_int) gearmand_log_gai_error(GEARMAN_DEFAULT_LOG_PARAM, (_gai_int), (_mesg))
  54. GEARMAN_INTERNAL_API
  55. gearmand_error_t gearmand_log_memory_error(const char *position, const char *function, const char *allocator, const char *type, size_t count, size_t size);
  56. #define gearmand_merror(__allocator, __object_type, __count) gearmand_log_memory_error(GEARMAN_DEFAULT_LOG_PARAM, (__allocator), (#__object_type), (__count), (sizeof(__object_type)))
  57. GEARMAN_INTERNAL_API
  58. void gearmand_log_notice(const char *position, const char *function, const char *format, ...);
  59. /**
  60. * Log an info message, see gearmand_log() for argument details.
  61. */
  62. GEARMAN_INTERNAL_API
  63. void gearmand_log_info(const char *position, const char *function, const char *format, ...);
  64. #define gearmand_info(_mesg) gearmand_log_info(GEARMAN_DEFAULT_LOG_PARAM, (_mesg))
  65. /**
  66. * Log an info message, see gearmand_log() for argument details.
  67. */
  68. GEARMAN_INTERNAL_API
  69. void gearmand_log_warning(const char *position, const char *function, const char *format, ...);
  70. #define gearmand_warning(_mesg) gearmand_log_warning(GEARMAN_DEFAULT_LOG_PARAM, (_mesg))
  71. /**
  72. * Log a debug message, see gearmand_log() for argument details.
  73. */
  74. GEARMAN_INTERNAL_API
  75. void gearmand_log_debug(const char *position, const char *function, const char *format, ...);
  76. #define gearmand_debug(_mesg) gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM, (_mesg))
  77. #ifdef __cplusplus
  78. }
  79. #endif