base.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2013 Hugh Bailey <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #pragma once
  17. #include <stdarg.h>
  18. #include "c99defs.h"
  19. /*
  20. * Just contains logging/crash related stuff
  21. */
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. enum {
  26. /**
  27. * Use if there's a problem that can potentially affect the program,
  28. * but isn't enough to require termination of the program.
  29. *
  30. * Use in creation functions and core subsystem functions. Places that
  31. * should definitely not fail.
  32. */
  33. LOG_ERROR = 100,
  34. /**
  35. * Use if a problem occurs that doesn't affect the program and is
  36. * recoverable.
  37. *
  38. * Use in places where where failure isn't entirely unexpected, and can
  39. * be handled safely.
  40. */
  41. LOG_WARNING = 200,
  42. /**
  43. * Informative essage to be displayed in the log.
  44. */
  45. LOG_INFO = 300,
  46. /**
  47. * Debug message to be used mostly by developers.
  48. */
  49. LOG_DEBUG = 400
  50. };
  51. EXPORT void base_set_log_handler(
  52. void (*handler)(int log_level, const char *, va_list));
  53. EXPORT void base_set_crash_handler(void (*handler)(const char *, va_list));
  54. EXPORT void blogva(int log_level, const char *format, va_list args);
  55. #ifndef _MSC_VER
  56. #define PRINTFATTR(f, a) __attribute__((__format__(__printf__, f, a)))
  57. #else
  58. #define PRINTFATTR(f, a)
  59. #endif
  60. PRINTFATTR(2, 3)
  61. EXPORT void blog(int log_level, const char *format, ...);
  62. PRINTFATTR(1, 2)
  63. EXPORT void bcrash(const char *format, ...);
  64. #undef PRINTFATTR
  65. #ifdef __cplusplus
  66. }
  67. #endif