logging.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. * This file is part of ToaruOS and is released under the terms
  3. * of the NCSA / University of Illinois License - see LICENSE.md
  4. * Copyright (C) 2011-2018 K. Lange
  5. *
  6. * Kernel Logging Facility
  7. *
  8. * Maintains a log in-memory as well as to serial (unless
  9. * told not to).
  10. */
  11. #include <kernel/system.h>
  12. #include <kernel/logging.h>
  13. #include <kernel/printf.h>
  14. #include <va_list.h>
  15. #include <toaru/list.h>
  16. log_type_t debug_level = NOTICE;
  17. void * debug_file = NULL;
  18. void (*debug_hook)(void *, char *) = NULL;
  19. void (*debug_video_crash)(char **) = NULL;
  20. static char * c_messages[] = {
  21. " \033[1;34mINFO\033[0m:",
  22. " \033[1;35mNOTICE\033[0m:",
  23. " \033[1;33mWARNING\033[0m:",
  24. " \033[1;31mERROR\033[0m:",
  25. " \033[1;37;41mCRITICAL\033[0m:",
  26. " \033[1;31;44mINSANE\033[0m:"
  27. };
  28. static char buffer[1024];
  29. void _debug_print(char * title, int line_no, log_type_t level, char *fmt, ...) {
  30. if (level >= debug_level && debug_file) {
  31. va_list args;
  32. va_start(args, fmt);
  33. vasprintf(buffer, fmt, args);
  34. va_end(args);
  35. char * type;
  36. if (level > INSANE) {
  37. type = "";
  38. } else {
  39. type = c_messages[level];
  40. }
  41. fprintf(debug_file, "[%10d.%3d:%s:%d]%s %s\n", timer_ticks, timer_subticks, title, line_no, type, buffer);
  42. }
  43. /* else ignore */
  44. }