FIRLogger.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. #import <FirebaseCore/FIRLoggerLevel.h>
  18. NS_ASSUME_NONNULL_BEGIN
  19. /**
  20. * The Firebase services used in Firebase logger.
  21. */
  22. typedef NSString *const FIRLoggerService;
  23. extern FIRLoggerService kFIRLoggerAnalytics;
  24. extern FIRLoggerService kFIRLoggerCrash;
  25. extern FIRLoggerService kFIRLoggerCore;
  26. extern FIRLoggerService 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. * Changes the default logging level of FirebaseLoggerLevelNotice to a user-specified level.
  47. * The default level cannot be set above FirebaseLoggerLevelNotice if the app is running from App
  48. * Store. (required) log level (one of the FirebaseLoggerLevel enum values).
  49. */
  50. void FIRSetLoggerLevel(FIRLoggerLevel loggerLevel);
  51. /**
  52. * Checks if the specified logger level is loggable given the current settings.
  53. * (required) log level (one of the FirebaseLoggerLevel enum values).
  54. * (required) whether or not this function is called from the Analytics component.
  55. */
  56. BOOL FIRIsLoggableLevel(FIRLoggerLevel loggerLevel, BOOL analyticsComponent);
  57. /**
  58. * Logs a message to the Xcode console and the device log. If running from AppStore, will
  59. * not log any messages with a level higher than FirebaseLoggerLevelNotice to avoid log spamming.
  60. * (required) log level (one of the FirebaseLoggerLevel enum values).
  61. * (required) service name of type FirebaseLoggerService.
  62. * (required) message code starting with "I-" which means iOS, followed by a capitalized
  63. * three-character service identifier and a six digit integer message ID that is unique
  64. * within the service.
  65. * An example of the message code is @"I-COR000001".
  66. * (required) message string which can be a format string.
  67. * (optional) variable arguments list obtained from calling va_start, used when message is a format
  68. * string.
  69. */
  70. extern void FIRLogBasic(FIRLoggerLevel level,
  71. FIRLoggerService service,
  72. NSString *messageCode,
  73. NSString *message,
  74. // On 64-bit simulators, va_list is not a pointer, so cannot be marked nullable
  75. // See: http://stackoverflow.com/q/29095469
  76. #if __LP64__ && TARGET_OS_SIMULATOR || TARGET_OS_OSX
  77. va_list args_ptr
  78. #else
  79. va_list _Nullable args_ptr
  80. #endif
  81. );
  82. /**
  83. * The following functions accept the following parameters in order:
  84. * (required) service name of type FirebaseLoggerService.
  85. * (required) message code starting from "I-" which means iOS, followed by a capitalized
  86. * three-character service identifier and a six digit integer message ID that is unique
  87. * within the service.
  88. * An example of the message code is @"I-COR000001".
  89. * See go/firebase-log-proposal for details.
  90. * (required) message string which can be a format string.
  91. * (optional) the list of arguments to substitute into the format string.
  92. * Example usage:
  93. * FirebaseLogError(kFirebaseLoggerCore, @"I-COR000001", @"Configuration of %@ failed.", app.name);
  94. */
  95. extern void FIRLogError(FIRLoggerService service, NSString *messageCode, NSString *message, ...)
  96. NS_FORMAT_FUNCTION(3, 4);
  97. extern void FIRLogWarning(FIRLoggerService service, NSString *messageCode, NSString *message, ...)
  98. NS_FORMAT_FUNCTION(3, 4);
  99. extern void FIRLogNotice(FIRLoggerService service, NSString *messageCode, NSString *message, ...)
  100. NS_FORMAT_FUNCTION(3, 4);
  101. extern void FIRLogInfo(FIRLoggerService service, NSString *messageCode, NSString *message, ...)
  102. NS_FORMAT_FUNCTION(3, 4);
  103. extern void FIRLogDebug(FIRLoggerService service, NSString *messageCode, NSString *message, ...)
  104. NS_FORMAT_FUNCTION(3, 4);
  105. // TODO: Come up with a better logging scheme for Swift.
  106. /**
  107. * Logs a debug message to the Xcode console and the device log. If running from AppStore, will
  108. * not log any messages with a level higher than FirebaseLoggerLevelNotice to avoid log spamming.
  109. * This function is intended to be used by Swift clients that do not support variadic parameters.
  110. *
  111. * @param service The service name of type `FirebaseLoggerService`.
  112. * @param messageCode The mesage code. starting with "I-" which means iOS, followed by a capitalized
  113. * three-character service identifier and a six digit integer message ID that is unique within the
  114. * service. An example of the message code is @"I-COR000001".
  115. * @param message The message string.
  116. */
  117. extern void FIRLogDebugSwift(FIRLoggerService service, NSString *messageCode, NSString *message);
  118. /**
  119. * Logs a warning message to the Xcode console and the device log. If running from AppStore, will
  120. * not log any messages with a level higher than FirebaseLoggerLevelNotice to avoid log spamming.
  121. * This function is intended to be used by Swift clients that do not support variadic parameters.
  122. *
  123. * @param service The service name of type `FirebaseLoggerService`.
  124. * @param messageCode The mesage code. starting with "I-" which means iOS, followed by a capitalized
  125. * three-character service identifier and a six digit integer message ID that is unique within the
  126. * service. An example of the message code is @"I-COR000001".
  127. * @param message The message string.
  128. */
  129. extern void FIRLogWarningSwift(FIRLoggerService service, NSString *messageCode, NSString *message);
  130. #ifdef __cplusplus
  131. } // extern "C"
  132. #endif // __cplusplus
  133. NS_SWIFT_NAME(FirebaseLogger)
  134. @interface FIRLoggerWrapper : NSObject
  135. /// Logs a given message at a given log level. This API is effectively a wrapper for the
  136. /// `FIRLogBasic` C API.
  137. ///
  138. /// - Parameters:
  139. /// - level: The log level to use (defined by `FirebaseLoggerLevel` enum values).
  140. /// - service: The service name of type `FirebaseLoggerService`.
  141. /// - code: The mesage code. Starting with "I-" which means iOS, followed by a capitalized
  142. /// three-character service identifier and a six digit integer message ID that is unique within
  143. /// the service. An example of the message code is @"I-COR000001".
  144. /// - message: Formatted string to be used as the log's message.
  145. /// - args: Arguments list obtained from calling `va_start`, used when message is a format string.
  146. + (void)logWithLevel:(FIRLoggerLevel)level
  147. withService:(FIRLoggerService)service
  148. withCode:(NSString *)messageCode
  149. withMessage:(NSString *)message
  150. withArgs:(va_list)args;
  151. /// Logs a given message at a given log level.
  152. ///
  153. /// - Parameters:
  154. /// - level: The log level to use (defined by `FirebaseLoggerLevel` enum values).
  155. /// - service: The service name of type `FirebaseLoggerService`.
  156. /// - code: The mesage code. Starting with "I-" which means iOS, followed by a capitalized
  157. /// three-character service identifier and a six digit integer message ID that is unique within
  158. /// the service. An example of the message code is @"I-COR000001".
  159. /// - message: Formatted string to be used as the log's message.
  160. /// - args: Arguments list obtained from calling `va_start`, used when message is a format string.
  161. + (void)logWithLevel:(FIRLoggerLevel)level
  162. service:(FIRLoggerService)service
  163. code:(NSString *)code
  164. message:(NSString *)message
  165. __attribute__((__swift_name__("log(level:service:code:message:)")));
  166. @end
  167. NS_ASSUME_NONNULL_END