2
0

qemu-log.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef QEMU_LOG_H
  2. #define QEMU_LOG_H
  3. /* The deprecated global variables: */
  4. extern FILE *logfile;
  5. extern int loglevel;
  6. /*
  7. * The new API:
  8. *
  9. */
  10. /* Log settings checking macros: */
  11. /* Returns true if qemu_log() will really write somewhere
  12. */
  13. #define qemu_log_enabled() (logfile != NULL)
  14. /* Returns true if a bit is set in the current loglevel mask
  15. */
  16. #define qemu_loglevel_mask(b) ((loglevel & (b)) != 0)
  17. /* Logging functions: */
  18. /* main logging function
  19. */
  20. #define qemu_log(...) do { \
  21. if (logfile) \
  22. fprintf(logfile, ## __VA_ARGS__); \
  23. } while (0)
  24. /* vfprintf-like logging function
  25. */
  26. #define qemu_log_vprintf(fmt, va) do { \
  27. if (logfile) \
  28. vfprintf(logfile, fmt, va); \
  29. } while (0)
  30. /* log only if a bit is set on the current loglevel mask
  31. */
  32. #define qemu_log_mask(b, ...) do { \
  33. if (loglevel & (b)) \
  34. fprintf(logfile, ## __VA_ARGS__); \
  35. } while (0)
  36. /* Special cases: */
  37. /* cpu_dump_state() logging functions: */
  38. #define log_cpu_state(env, f) cpu_dump_state((env), logfile, fprintf, (f));
  39. #define log_cpu_state_mask(b, env, f) do { \
  40. if (loglevel & (b)) log_cpu_state((env), (f)); \
  41. } while (0)
  42. /* disas() and target_disas() to logfile: */
  43. #define log_target_disas(start, len, flags) \
  44. target_disas(logfile, (start), (len), (flags))
  45. #define log_disas(start, len) \
  46. disas(logfile, (start), (len))
  47. /* page_dump() output to the log file: */
  48. #define log_page_dump() page_dump(logfile)
  49. /* Maintenance: */
  50. /* fflush() the log file */
  51. #define qemu_log_flush() fflush(logfile)
  52. /* Close the log file */
  53. #define qemu_log_close() do { \
  54. fclose(logfile); \
  55. logfile = NULL; \
  56. } while (0)
  57. /* Set up a new log file */
  58. #define qemu_log_set_file(f) do { \
  59. logfile = (f); \
  60. } while (0)
  61. /* Set up a new log file, only if none is set */
  62. #define qemu_log_try_set_file(f) do { \
  63. if (!logfile) \
  64. logfile = (f); \
  65. } while (0)
  66. #endif