log.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #define log_emerg(format, ...) \
  63. log_msg(LOG_EMERG, (format), ##__VA_ARGS__)
  64. #define log_alert(format, ...) \
  65. log_msg(LOG_ALERT, (format), ##__VA_ARGS__)
  66. #define log_crit(format, ...) \
  67. log_msg(LOG_CRIT, (format), ##__VA_ARGS__)
  68. #define log_err(format, ...) \
  69. log_msg(LOG_ERR, (format), ##__VA_ARGS__)
  70. #define log_warning(format, ...) \
  71. log_msg(LOG_WARNING, (format), ##__VA_ARGS__)
  72. #define log_notice(format, ...) \
  73. log_msg(LOG_NOTICE, (format), ##__VA_ARGS__)
  74. #define log_info(format, ...) \
  75. log_msg(LOG_INFO, (format), ##__VA_ARGS__)
  76. #define log_debug(format, ...) \
  77. log_msg(LOG_DEBUG, (format), ##__VA_ARGS__)
  78. /*
  79. * The bulletin returned by this function is used to notify the initial log
  80. * dump so that console output is well ordered.
  81. */
  82. struct bulletin * log_get_bulletin(void);
  83. /*
  84. * This init operation provides :
  85. * - message logging
  86. *
  87. * The log thread isn't yet started and messages are merely stored in an
  88. * internal buffer.
  89. */
  90. INIT_OP_DECLARE(log_setup);
  91. #endif /* KERN_LOG_H */