log.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2017-2019 Richard Braun.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. *
  18. * System logging.
  19. */
  20. #ifndef KERN_LOG_H
  21. #define KERN_LOG_H
  22. #include <stdarg.h>
  23. #include <kern/init.h>
  24. enum {
  25. LOG_EMERG,
  26. LOG_ALERT,
  27. LOG_CRIT,
  28. LOG_ERR,
  29. LOG_WARNING,
  30. LOG_NOTICE,
  31. LOG_INFO,
  32. LOG_DEBUG,
  33. LOG_NR_LEVELS,
  34. };
  35. /*
  36. * Type for function pointers that may be used as either a log function
  37. * or printf.
  38. *
  39. * One call to a log print function produces a single log line, with a
  40. * newline character.
  41. */
  42. typedef int (*log_print_fn_t)(const char *format, ...)
  43. __attribute__((format(printf, 1, 2)));
  44. /*
  45. * Generate a message and send it to the log thread.
  46. *
  47. * The arguments and return value are similar to printf(), with
  48. * these exceptions :
  49. * - a level is associated to each log message
  50. * - processing stops at the first terminating null byte or newline
  51. * character, whichever occurs first
  52. *
  53. * This function may safely be called in interrupt context.
  54. */
  55. int log_msg(unsigned int level, const char *format, ...)
  56. __attribute__((format(printf, 2, 3)));
  57. int log_vmsg(unsigned int level, const char *format, va_list ap)
  58. __attribute__((format(printf, 2, 0)));
  59. /*
  60. * Convenience wrappers.
  61. */
  62. int log_emerg(const char *format, ...) __attribute__((format(printf, 1, 2)));
  63. int log_alert(const char *format, ...) __attribute__((format(printf, 1, 2)));
  64. int log_crit(const char *format, ...) __attribute__((format(printf, 1, 2)));
  65. int log_err(const char *format, ...) __attribute__((format(printf, 1, 2)));
  66. int log_warning(const char *format, ...) __attribute__((format(printf, 1, 2)));
  67. int log_notice(const char *format, ...) __attribute__((format(printf, 1, 2)));
  68. int log_info(const char *format, ...) __attribute__((format(printf, 1, 2)));
  69. int log_debug(const char *format, ...) __attribute__((format(printf, 1, 2)));
  70. int log_vemerg(const char *format, va_list ap)
  71. __attribute__((format(printf, 1, 0)));
  72. int log_valert(const char *format, va_list ap)
  73. __attribute__((format(printf, 1, 0)));
  74. int log_vcrit(const char *format, va_list ap)
  75. __attribute__((format(printf, 1, 0)));
  76. int log_verr(const char *format, va_list ap)
  77. __attribute__((format(printf, 1, 0)));
  78. int log_vwarning(const char *format, va_list ap)
  79. __attribute__((format(printf, 1, 0)));
  80. int log_vnotice(const char *format, va_list ap)
  81. __attribute__((format(printf, 1, 0)));
  82. int log_vinfo(const char *format, va_list ap)
  83. __attribute__((format(printf, 1, 0)));
  84. int log_vdebug(const char *format, va_list ap)
  85. __attribute__((format(printf, 1, 0)));
  86. /*
  87. * The bulletin returned by this function is used to notify the initial log
  88. * dump so that console output is well ordered.
  89. */
  90. struct bulletin * log_get_bulletin(void);
  91. /*
  92. * This init operation provides :
  93. * - message logging
  94. *
  95. * The log thread isn't yet started and messages are merely stored in an
  96. * internal buffer.
  97. */
  98. INIT_OP_DECLARE(log_setup);
  99. #endif /* KERN_LOG_H */