RLMLogger.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2023 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import <Realm/RLMConstants.h>
  19. RLM_HEADER_AUDIT_BEGIN(nullability)
  20. /// An enum representing different levels of sync-related logging that can be configured.
  21. typedef RLM_CLOSED_ENUM(NSUInteger, RLMLogLevel) {
  22. /// Nothing will ever be logged.
  23. RLMLogLevelOff,
  24. /// Only fatal errors will be logged.
  25. RLMLogLevelFatal,
  26. /// Only errors will be logged.
  27. RLMLogLevelError,
  28. /// Warnings and errors will be logged.
  29. RLMLogLevelWarn,
  30. /// Information about sync events will be logged. Fewer events will be logged in order to avoid overhead.
  31. RLMLogLevelInfo,
  32. /// Information about sync events will be logged. More events will be logged than with `RLMLogLevelInfo`.
  33. RLMLogLevelDetail,
  34. /// Log information that can aid in debugging.
  35. ///
  36. /// - warning: Will incur a measurable performance impact.
  37. RLMLogLevelDebug,
  38. /// Log information that can aid in debugging. More events will be logged than with `RLMLogLevelDebug`.
  39. ///
  40. /// - warning: Will incur a measurable performance impact.
  41. RLMLogLevelTrace,
  42. /// Log information that can aid in debugging. More events will be logged than with `RLMLogLevelTrace`.
  43. ///
  44. /// - warning: Will incur a measurable performance impact.
  45. RLMLogLevelAll
  46. } NS_SWIFT_NAME(LogLevel);
  47. /// A log callback function which can be set on RLMLogger.
  48. ///
  49. /// The log function may be called from multiple threads simultaneously, and is
  50. /// responsible for performing its own synchronization if any is required.
  51. RLM_SWIFT_SENDABLE // invoked on a background thread
  52. typedef void (^RLMLogFunction)(RLMLogLevel level, NSString *message);
  53. /**
  54. `RLMLogger` is used for creating your own custom logging logic.
  55. You can define your own logger creating an instance of `RLMLogger` and define the log function which will be
  56. invoked whenever there is a log message.
  57. Set this custom logger as you default logger using `setDefaultLogger`.
  58. RLMLogger.defaultLogger = [[RLMLogger alloc] initWithLevel:RLMLogLevelDebug
  59. logFunction:^(RLMLogLevel level, NSString * message) {
  60. NSLog(@"Realm Log - %lu, %@", (unsigned long)level, message);
  61. }];
  62. @note By default default log threshold level is `RLMLogLevelInfo`, and logging strings are output to Apple System Logger.
  63. */
  64. @interface RLMLogger : NSObject
  65. /**
  66. Gets the logging threshold level used by the logger.
  67. */
  68. @property (nonatomic) RLMLogLevel level;
  69. /// :nodoc:
  70. - (instancetype)init NS_UNAVAILABLE;
  71. /**
  72. Creates a logger with the associated log level and the logic function to define your own logging logic.
  73. @param level The log level to be set for the logger.
  74. @param logFunction The log function which will be invoked whenever there is a log message.
  75. */
  76. - (instancetype)initWithLevel:(RLMLogLevel)level logFunction:(RLMLogFunction)logFunction;
  77. #pragma mark RLMLogger Default Logger API
  78. /**
  79. The current default logger. When setting a logger as default, this logger will be used whenever information must be logged.
  80. */
  81. @property (class) RLMLogger *defaultLogger NS_SWIFT_NAME(shared);
  82. @end
  83. RLM_HEADER_AUDIT_END(nullability)