gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.5KB

  1. /*-------------------------------------------------------------------------
  2. * Logging framework for frontend programs
  3. *
  4. * Copyright (c) 2018-2019, PostgreSQL Global Development Group
  5. *
  6. * src/include/common/logging.h
  7. *
  8. *-------------------------------------------------------------------------
  9. */
  10. #ifndef COMMON_LOGGING_H
  11. #define COMMON_LOGGING_H
  12. /*
  13. * Log levels are informational only. They do not affect program flow.
  14. */
  15. enum pg_log_level
  16. {
  17. /*
  18. * Not initialized yet
  19. */
  20. PG_LOG_NOTSET = 0,
  21. /*
  22. * Low level messages that are normally off by default.
  23. */
  24. PG_LOG_DEBUG,
  25. /*
  26. * Any program messages that go to stderr, shown by default. (The
  27. * program's normal output should go to stdout and not use the logging
  28. * system.)
  29. */
  30. PG_LOG_INFO,
  31. /*
  32. * Warnings and "almost" errors, depends on the program
  33. */
  34. PG_LOG_WARNING,
  35. /*
  36. * Errors
  37. */
  38. PG_LOG_ERROR,
  39. /*
  40. * Severe errors that cause program termination. (One-shot programs may
  41. * chose to label even fatal errors as merely "errors". The distinction
  42. * is up to the program.)
  43. */
  44. PG_LOG_FATAL,
  45. /*
  46. * Turn all logging off.
  47. */
  48. PG_LOG_OFF,
  49. };
  50. extern enum pg_log_level __pg_log_level;
  51. /*
  52. * Kind of a hack to be able to produce the psql output exactly as required by
  53. * the regression tests.
  54. */
  55. #define PG_LOG_FLAG_TERSE 1
  56. void pg_logging_init(const char *argv0);
  57. void pg_logging_config(int new_flags);
  58. void pg_logging_set_level(enum pg_log_level new_level);
  59. void pg_logging_set_pre_callback(void (*cb) (void));
  60. void pg_logging_set_locus_callback(void (*cb) (const char **filename, uint64 *lineno));
  61. void pg_log_generic(enum pg_log_level level, const char *pg_restrict fmt,...) pg_attribute_printf(2, 3);
  62. void pg_log_generic_v(enum pg_log_level level, const char *pg_restrict fmt, va_list ap) pg_attribute_printf(2, 0);
  63. #define pg_log_fatal(...) do { \
  64. if (likely(__pg_log_level <= PG_LOG_FATAL)) pg_log_generic(PG_LOG_FATAL, __VA_ARGS__); \
  65. } while(0)
  66. #define pg_log_error(...) do { \
  67. if (likely(__pg_log_level <= PG_LOG_ERROR)) pg_log_generic(PG_LOG_ERROR, __VA_ARGS__); \
  68. } while(0)
  69. #define pg_log_warning(...) do { \
  70. if (likely(__pg_log_level <= PG_LOG_WARNING)) pg_log_generic(PG_LOG_WARNING, __VA_ARGS__); \
  71. } while(0)
  72. #define pg_log_info(...) do { \
  73. if (likely(__pg_log_level <= PG_LOG_INFO)) pg_log_generic(PG_LOG_INFO, __VA_ARGS__); \
  74. } while(0)
  75. #define pg_log_debug(...) do { \
  76. if (unlikely(__pg_log_level <= PG_LOG_DEBUG)) pg_log_generic(PG_LOG_DEBUG, __VA_ARGS__); \
  77. } while(0)
  78. #endif /* COMMON_LOGGING_H */
上海开阖软件有限公司 沪ICP备12045867号-1