logging_api.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * SRT - Secure, Reliable, Transport
  3. * Copyright (c) 2018 Haivision Systems Inc.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. *
  9. */
  10. /*****************************************************************************
  11. written by
  12. Haivision Systems Inc.
  13. *****************************************************************************/
  14. #ifndef INC_SRT_LOGGING_API_H
  15. #define INC_SRT_LOGGING_API_H
  16. // These are required for access functions:
  17. // - adding FA (requires set)
  18. // - setting a log stream (requires iostream)
  19. #ifdef __cplusplus
  20. #include <set>
  21. #include <iostream>
  22. #endif
  23. #ifdef _WIN32
  24. #include "win/syslog_defs.h"
  25. #else
  26. #include <syslog.h>
  27. #endif
  28. // Syslog is included so that it provides log level names.
  29. // Haivision log standard requires the same names plus extra one:
  30. #ifndef LOG_DEBUG_TRACE
  31. #define LOG_DEBUG_TRACE 8
  32. #endif
  33. // It's unused anyway, just for the record.
  34. #define SRT_LOG_LEVEL_MIN LOG_CRIT
  35. #define SRT_LOG_LEVEL_MAX LOG_DEBUG
  36. // Flags
  37. #define SRT_LOGF_DISABLE_TIME 1
  38. #define SRT_LOGF_DISABLE_THREADNAME 2
  39. #define SRT_LOGF_DISABLE_SEVERITY 4
  40. #define SRT_LOGF_DISABLE_EOL 8
  41. // Handler type.
  42. typedef void SRT_LOG_HANDLER_FN(void* opaque, int level, const char* file, int line, const char* area, const char* message);
  43. #ifdef __cplusplus
  44. namespace srt_logging
  45. {
  46. struct LogFA
  47. {
  48. private:
  49. int value;
  50. public:
  51. operator int() const { return value; }
  52. LogFA(int v): value(v)
  53. {
  54. // Generally this was what it has to be used for.
  55. // Unfortunately it couldn't be agreed with the
  56. //logging_fa_all.insert(v);
  57. }
  58. };
  59. const LogFA LOGFA_GENERAL = 0;
  60. namespace LogLevel
  61. {
  62. // There are 3 general levels:
  63. // A. fatal - this means the application WILL crash.
  64. // B. unexpected:
  65. // - error: this was unexpected for the library
  66. // - warning: this was expected by the library, but may be harmful for the application
  67. // C. expected:
  68. // - note: a significant, but rarely occurring event
  69. // - debug: may occur even very often and enabling it can harm performance
  70. enum type
  71. {
  72. fatal = LOG_CRIT,
  73. // Fatal vs. Error: with Error, you can still continue.
  74. error = LOG_ERR,
  75. // Error vs. Warning: Warning isn't considered a problem for the library.
  76. warning = LOG_WARNING,
  77. // Warning vs. Note: Note means something unusual, but completely correct behavior.
  78. note = LOG_NOTICE,
  79. // Note vs. Debug: Debug may occur even multiple times in a millisecond.
  80. // (Well, worth noting that Error and Warning potentially also can).
  81. debug = LOG_DEBUG
  82. };
  83. }
  84. class Logger;
  85. }
  86. #endif
  87. #endif