You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.1 KiB

1 year ago
  1. /**
  2. * @file Log.h
  3. * @brief Log interfaces.
  4. * @copyright VisionLabs LLC
  5. * @date 20.02.2018
  6. * */
  7. #pragma once
  8. #include <fsdk/Def.h>
  9. namespace fsdk{
  10. namespace log {
  11. /**
  12. * @brief Custom print function type.
  13. * */
  14. using PrintFunction = void (*)(int severity, const char* message);
  15. /**
  16. * @brief Log message severity enumeration.
  17. * */
  18. enum Severity
  19. {
  20. SV_ERROR=1, //!< Critical error.
  21. SV_WARN, //!< Recoverable error / non-critical issue.
  22. SV_INFO, //!< Generic information.
  23. SV_DEBUG, //!< Extended (debugging) information (verbose).
  24. #ifndef NDEBUG
  25. SV_DEFAULT = SV_DEBUG //!< Default severity.
  26. #else
  27. SV_DEFAULT = SV_INFO //!< Default severity.
  28. #endif
  29. };
  30. /**
  31. * @brief Set print function pointer. Default function is made thread-safe with function-local mutex.
  32. * It means that if you provide your custom print function it's your duty to make it thread safe or not thread safe.
  33. * @param [in] function new function pointer. @see PrintFunction.
  34. * Any exception thrown out of param function is catched, but not throwing is
  35. * better idea still.
  36. * */
  37. FSDK_API void setPrintFunction(PrintFunction function) noexcept;
  38. /**
  39. * @brief Get print function pointer.
  40. * @returns print function pointer. @see PrintFunction.
  41. * */
  42. FSDK_API PrintFunction getPrintFunction() noexcept;
  43. /**
  44. * @brief Get default print function pointer. Is thread-safe.
  45. * @returns print function pointer. @see PrintFunction.
  46. * */
  47. FSDK_API PrintFunction getDefaultPrintFunction() noexcept;
  48. /**
  49. * @brief Helper function to restore default print function.
  50. * @detais This is equivalent to:
  51. * @code
  52. * setPrintFunction(getDefaultPrintFunction());
  53. * @endcode
  54. * */
  55. FSDK_API void restorePrintFunction() noexcept;
  56. /**
  57. * @brief Sets severity logging filter
  58. * @param [in] severity desired severity filter. @see Severity.
  59. * */
  60. FSDK_API void setSeverityFilter(int severity) noexcept;
  61. /** @brief Get log severity filter.
  62. * @returns severity level. @see Severity.
  63. */
  64. FSDK_API int getSeverityFilter() noexcept;
  65. }
  66. }