You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
5.7 KiB

  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 kFIRLoggerMLKit;
  27. extern FIRLoggerService kFIRLoggerPerf;
  28. extern FIRLoggerService 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 YES, the logging level for Analytics will be set to FIRLoggerLevelDebug.
  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. * Changes the default logging level of FIRLoggerLevelNotice to a user-specified level.
  49. * The default level cannot be set above FIRLoggerLevelNotice if the app is running from App Store.
  50. * (required) log level (one of the FIRLoggerLevel enum values).
  51. */
  52. void FIRSetLoggerLevel(FIRLoggerLevel loggerLevel);
  53. /**
  54. * Checks if the specified logger level is loggable given the current settings.
  55. * (required) log level (one of the FIRLoggerLevel enum values).
  56. * (required) whether or not this function is called from the Analytics component.
  57. */
  58. BOOL FIRIsLoggableLevel(FIRLoggerLevel loggerLevel, BOOL analyticsComponent);
  59. /**
  60. * Logs a message to the Xcode console and the device log. If running from AppStore, will
  61. * not log any messages with a level higher than FIRLoggerLevelNotice to avoid log spamming.
  62. * (required) log level (one of the FIRLoggerLevel enum values).
  63. * (required) service name of type FIRLoggerService.
  64. * (required) message code starting with "I-" which means iOS, followed by a capitalized
  65. * three-character service identifier and a six digit integer message ID that is unique
  66. * within the service.
  67. * An example of the message code is @"I-COR000001".
  68. * (required) message string which can be a format string.
  69. * (optional) variable arguments list obtained from calling va_start, used when message is a format
  70. * string.
  71. */
  72. extern void FIRLogBasic(FIRLoggerLevel level,
  73. FIRLoggerService service,
  74. NSString *messageCode,
  75. NSString *message,
  76. // On 64-bit simulators, va_list is not a pointer, so cannot be marked nullable
  77. // See: http://stackoverflow.com/q/29095469
  78. #if __LP64__ && TARGET_OS_SIMULATOR || TARGET_OS_OSX
  79. va_list args_ptr
  80. #else
  81. va_list _Nullable args_ptr
  82. #endif
  83. );
  84. /**
  85. * The following functions accept the following parameters in order:
  86. * (required) service name of type FIRLoggerService.
  87. * (required) message code starting from "I-" which means iOS, followed by a capitalized
  88. * three-character service identifier and a six digit integer message ID that is unique
  89. * within the service.
  90. * An example of the message code is @"I-COR000001".
  91. * See go/firebase-log-proposal for details.
  92. * (required) message string which can be a format string.
  93. * (optional) the list of arguments to substitute into the format string.
  94. * Example usage:
  95. * FIRLogError(kFIRLoggerCore, @"I-COR000001", @"Configuration of %@ failed.", app.name);
  96. */
  97. extern void FIRLogError(FIRLoggerService service, NSString *messageCode, NSString *message, ...)
  98. NS_FORMAT_FUNCTION(3, 4);
  99. extern void FIRLogWarning(FIRLoggerService service, NSString *messageCode, NSString *message, ...)
  100. NS_FORMAT_FUNCTION(3, 4);
  101. extern void FIRLogNotice(FIRLoggerService service, NSString *messageCode, NSString *message, ...)
  102. NS_FORMAT_FUNCTION(3, 4);
  103. extern void FIRLogInfo(FIRLoggerService service, NSString *messageCode, NSString *message, ...)
  104. NS_FORMAT_FUNCTION(3, 4);
  105. extern void FIRLogDebug(FIRLoggerService service, NSString *messageCode, NSString *message, ...)
  106. NS_FORMAT_FUNCTION(3, 4);
  107. #ifdef __cplusplus
  108. } // extern "C"
  109. #endif // __cplusplus
  110. @interface FIRLoggerWrapper : NSObject
  111. /**
  112. * Objective-C wrapper for FIRLogBasic to allow weak linking to FIRLogger
  113. * (required) log level (one of the FIRLoggerLevel enum values).
  114. * (required) service name of type FIRLoggerService.
  115. * (required) message code starting with "I-" which means iOS, followed by a capitalized
  116. * three-character service identifier and a six digit integer message ID that is unique
  117. * within the service.
  118. * An example of the message code is @"I-COR000001".
  119. * (required) message string which can be a format string.
  120. * (optional) variable arguments list obtained from calling va_start, used when message is a format
  121. * string.
  122. */
  123. + (void)logWithLevel:(FIRLoggerLevel)level
  124. withService:(FIRLoggerService)service
  125. withCode:(NSString *)messageCode
  126. withMessage:(NSString *)message
  127. withArgs:(va_list)args;
  128. @end
  129. NS_ASSUME_NONNULL_END