logging-api.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. _ _ _ ____ ___
  2. | | ___ __ _ __ _(_)_ __ __ _ / \ | _ \_ _|
  3. | | / _ \ / _` |/ _` | | '_ \ / _` | / _ \ | |_) | |
  4. | |__| (_) | (_| | (_| | | | | | (_| | / ___ \| __/| |
  5. |_____\___/ \__, |\__, |_|_| |_|\__, | /_/ \_\_| |___|
  6. |___/ |___/ |___/
  7. Ondrej Martinek <[email protected]>
  8. January 2009
  9. This document contains the short description of the logging API in Kamailio
  10. for developers.
  11. Source files:
  12. dprint.h
  13. dprint.c
  14. Compile-time control macros
  15. =============================
  16. NO_LOG
  17. If defined, logging is completely disabled in SER and no messages
  18. are produced at all
  19. NO_DEBUG
  20. If defined, logging messages do not include the source filename and
  21. line location info
  22. Logging levels
  23. ================
  24. L_DBG ... Debugging message (the lowest level)
  25. L_INFO ... Info message
  26. L_WARN ... Warning message
  27. L_ERR ... Error message
  28. L_CRIT ... Critical message
  29. L_ALERT ... Alert message (the highest level)
  30. The levels are implemented as integer macros.
  31. Related variables
  32. ===================
  33. debug
  34. The config.framework setting that contains the current logging level.
  35. The initial value can be specified by "debug" parameter in ser.cfg or
  36. by -d options on the command-line. The default value is L_WARN.
  37. log_stderror
  38. The global variable which specifies whether the log messages should be
  39. send to the standard error output or syslog (equals to zero).
  40. Its value can be specified by "log_stderr" parameter in ser.cfg or
  41. -E option on the command-line.
  42. log_facility
  43. The config.framework setting that contains the current facility for
  44. logging to syslog.
  45. The initial value can be specified by "log_facility" parameter in
  46. ser.cfg. The default value is LOG_DAEMON.
  47. Macro functions
  48. =================
  49. * short macro aliases:
  50. DBG(FMT, ARGS...) alias for LOG(L_DBG, FMT, ARGS...)
  51. INFO(FMT, ARGS...) alias for LOG(L_INFO, FMT, ARGS...)
  52. WARN(FMT, ARGS...) alias for LOG(L_WARN, FMT, ARGS...)
  53. ERR(FMT, ARGS...) alias for LOG(L_ERR, FMT, ARGS...)
  54. BUG(FMT, ARGS...) alias for LOG(L_CRIT, FMT, ARGS...)
  55. ALERT(FMT, ARGS...) alias for LOG(L_ALERT, FMT, ARGS...)
  56. * LOG(LEVEL, FMT, ARGS...) macro
  57. Prints the log message on stderr or syslog if the current debug level
  58. is greater or equal to LEVEL. The message has the following format:
  59. - for messages by core:
  60. PROC(PID) LEVEL: <core> [FILE:LINE]: MESSAGE
  61. - for messages by modules:
  62. PROC(PID) LEVEL: MODULE [FILE:LINE]: MESSAGE
  63. - for messages by log(), xlog(), xdbg() script functions:
  64. PROC(PID) LEVEL: <script>: MESSAGE
  65. PROC is the SER process number and PID is the linux process ID.
  66. LEVEL is one of "DEBUG", "INFO", "NOTICE", "WARNING", "ERROR",
  67. "ALERT" and "BUG" strings. MESSAGE is constructed from printf-like
  68. arguments FMT and ARGS.
  69. [FILE:LINE] location info is not present if NO_DEBUG macro is defined.
  70. Use of shorter aliases is preferred if LEVEL is a preprocess-time
  71. constant.
  72. * LOG_(LEVEL, PREFIX, FMT, ARGS...) macro
  73. Prints the log message on stderr or syslog if the current debug level
  74. is greater or equal to LEVEL. The message has the following format:
  75. PROC(PID) LEVEL: PREFIXMESSAGE
  76. This is an internal macro try to avoid using it.
  77. --------------------------------------------------------------------------------
  78. APPENDIX: Summary of the changes to the original API
  79. ======================================================
  80. - LOG(LEVEL, FMT, ARGS...) and the short macro corresponding to LEVEL level
  81. made eqvivalent (eg. LOG(L_DBG, FMT, ARGS...) and DBG(FMT, ARGS...) prints
  82. always the same message)
  83. - changed the format of log messages produced by the macros to include
  84. the log level, module name, filename, line (if applicable)
  85. - added new, internal LOG_(LEVEL, PREFIX, FORMAT, ARGS...) macro
  86. - removed DPrint() and DEBUG() macros, L_DEFAULT log level and dprint()
  87. function
  88. !!!
  89. !!! IMPORTANT! READ ME!
  90. !!!
  91. !!! These changes (mainly the first two) require reformating of the most log
  92. !!! messages in Kamailio core and module source files. This step can be done
  93. !!! automatically by running "scripts/logging/fix-logs-all" script BUT it
  94. !!! was NOT originally performed because it would have generated too many
  95. !!! changes in CVS which was discouraged by Andrei. Instead, the developers
  96. !!! are expected to run it when ready.
  97. !!!
  98. !!! IMPORTANT! READ ME!
  99. !!!