FIRLogger.h 7.7 KB

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