FIRLogger.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. typedef NS_ENUM(NSInteger, FIRLoggerLevel);
  18. NS_ASSUME_NONNULL_BEGIN
  19. /**
  20. * The Firebase services used in Firebase logger.
  21. */
  22. typedef NSString *const FIRLoggerService;
  23. extern NSString *const kFIRLoggerAnalytics;
  24. extern NSString *const kFIRLoggerCrash;
  25. extern NSString *const kFIRLoggerCore;
  26. extern NSString *const kFIRLoggerRemoteConfig;
  27. /**
  28. * The key used to store the logger's error count.
  29. */
  30. extern NSString *const kFIRLoggerErrorCountKey;
  31. /**
  32. * The key used to store the logger's warning count.
  33. */
  34. extern NSString *const kFIRLoggerWarningCountKey;
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif // __cplusplus
  38. /**
  39. * Enables or disables Analytics debug mode.
  40. * If set to true, the logging level for Analytics will be set to FirebaseLoggerLevelDebug.
  41. * Enabling the debug mode has no effect if the app is running from App Store.
  42. * (required) analytics debug mode flag.
  43. */
  44. void FIRSetAnalyticsDebugMode(BOOL analyticsDebugMode);
  45. /**
  46. * Gets the current FIRLoggerLevel.
  47. */
  48. FIRLoggerLevel FIRGetLoggerLevel(void);
  49. /**
  50. * Changes the default logging level of FirebaseLoggerLevelNotice to a user-specified level.
  51. * The default level cannot be set above FirebaseLoggerLevelNotice if the app is running from App
  52. * Store. (required) log level (one of the FirebaseLoggerLevel enum values).
  53. */
  54. void FIRSetLoggerLevel(FIRLoggerLevel loggerLevel);
  55. void FIRSetLoggerLevelNotice(void);
  56. void FIRSetLoggerLevelWarning(void);
  57. void FIRSetLoggerLevelError(void);
  58. void FIRSetLoggerLevelDebug(void);
  59. /**
  60. * Checks if the specified logger level is loggable given the current settings.
  61. * (required) log level (one of the FirebaseLoggerLevel enum values).
  62. * (required) whether or not this function is called from the Analytics component.
  63. */
  64. BOOL FIRIsLoggableLevel(FIRLoggerLevel loggerLevel, BOOL analyticsComponent);
  65. BOOL FIRIsLoggableLevelNotice(void);
  66. BOOL FIRIsLoggableLevelWarning(void);
  67. BOOL FIRIsLoggableLevelError(void);
  68. BOOL FIRIsLoggableLevelDebug(void);
  69. /**
  70. * Logs a message to the Xcode console and the device log. If running from AppStore, will
  71. * not log any messages with a level higher than FirebaseLoggerLevelNotice to avoid log spamming.
  72. * (required) log level (one of the FirebaseLoggerLevel enum values).
  73. * (required) service name of type FirebaseLoggerService.
  74. * (required) message code starting with "I-" which means iOS, followed by a capitalized
  75. * three-character service identifier and a six digit integer message ID that is unique
  76. * within the service.
  77. * An example of the message code is @"I-COR000001".
  78. * (required) message string which can be a format string.
  79. * (optional) variable arguments list obtained from calling va_start, used when message is a format
  80. * string.
  81. */
  82. extern void FIRLogBasic(FIRLoggerLevel level,
  83. NSString *category,
  84. NSString *messageCode,
  85. NSString *message,
  86. // On 64-bit simulators, va_list is not a pointer, so cannot be marked nullable
  87. // See: http://stackoverflow.com/q/29095469
  88. #if __LP64__ && TARGET_OS_SIMULATOR || TARGET_OS_OSX
  89. va_list args_ptr
  90. #else
  91. va_list _Nullable args_ptr
  92. #endif
  93. );
  94. /**
  95. * The following functions accept the following parameters in order:
  96. * (required) service name of type FirebaseLoggerService.
  97. * (required) message code starting from "I-" which means iOS, followed by a capitalized
  98. * three-character service identifier and a six digit integer message ID that is unique
  99. * within the service.
  100. * An example of the message code is @"I-COR000001".
  101. * See go/firebase-log-proposal for details.
  102. * (required) message string which can be a format string.
  103. * (optional) the list of arguments to substitute into the format string.
  104. * Example usage:
  105. * FirebaseLogError(kFirebaseLoggerCore, @"I-COR000001", @"Configuration of %@ failed.", app.name);
  106. */
  107. extern void FIRLogError(NSString *category, NSString *messageCode, NSString *message, ...)
  108. NS_FORMAT_FUNCTION(3, 4);
  109. extern void FIRLogWarning(NSString *category, NSString *messageCode, NSString *message, ...)
  110. NS_FORMAT_FUNCTION(3, 4);
  111. extern void FIRLogNotice(NSString *category, NSString *messageCode, NSString *message, ...)
  112. NS_FORMAT_FUNCTION(3, 4);
  113. extern void FIRLogInfo(NSString *category, NSString *messageCode, NSString *message, ...)
  114. NS_FORMAT_FUNCTION(3, 4);
  115. extern void FIRLogDebug(NSString *category, NSString *messageCode, NSString *message, ...)
  116. NS_FORMAT_FUNCTION(3, 4);
  117. /**
  118. * This function is similar to the one above, except it takes a `va_list` instead of the listed
  119. * variables.
  120. *
  121. * The following functions accept the following parameters in order: (required) service
  122. * name of type FirebaseLoggerService.
  123. *
  124. * (required) message code starting from "I-" which means iOS,
  125. * followed by a capitalized three-character service identifier and a six digit integer message
  126. * ID that is unique within the service. An example of the message code is @"I-COR000001".
  127. * See go/firebase-log-proposal for details.
  128. * (required) message string which can be a format string.
  129. * (optional) A va_list
  130. */
  131. extern void FIRLogBasicError(NSString *category,
  132. NSString *messageCode,
  133. NSString *message,
  134. va_list args_ptr);
  135. extern void FIRLogBasicWarning(NSString *category,
  136. NSString *messageCode,
  137. NSString *message,
  138. va_list args_ptr);
  139. extern void FIRLogBasicNotice(NSString *category,
  140. NSString *messageCode,
  141. NSString *message,
  142. va_list args_ptr);
  143. extern void FIRLogBasicInfo(NSString *category,
  144. NSString *messageCode,
  145. NSString *message,
  146. va_list args_ptr);
  147. extern void FIRLogBasicDebug(NSString *category,
  148. NSString *messageCode,
  149. NSString *message,
  150. va_list args_ptr);
  151. #ifdef __cplusplus
  152. } // extern "C"
  153. #endif // __cplusplus
  154. NS_SWIFT_NAME(FirebaseLogger)
  155. @interface FIRLoggerWrapper : NSObject
  156. /// Logs a given message at a given log level.
  157. ///
  158. /// - Parameters:
  159. /// - level: The log level to use (defined by `FirebaseLoggerLevel` enum values).
  160. /// - category: The service name of type `FirebaseLoggerService`.
  161. /// - code: The message code. Starting with "I-" which means iOS, followed by a capitalized
  162. /// three-character service identifier and a six digit integer message ID that is unique within
  163. /// the service. An example of the message code is @"I-COR000001".
  164. /// - message: Formatted string to be used as the log's message.
  165. + (void)logWithLevel:(FIRLoggerLevel)level
  166. service:(NSString *)category
  167. code:(NSString *)code
  168. message:(NSString *)message
  169. __attribute__((__swift_name__("log(level:service:code:message:)")));
  170. @end
  171. NS_ASSUME_NONNULL_END