FIRLogger.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 YES, the logging level for Analytics will be set to FIRLoggerLevelDebug.
  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 FIRLoggerLevelNotice to a user-specified level.
  47. * The default level cannot be set above FIRLoggerLevelNotice if the app is running from App Store.
  48. * (required) log level (one of the FIRLoggerLevel 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 FIRLoggerLevel 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 FIRLoggerLevelNotice to avoid log spamming.
  60. * (required) log level (one of the FIRLoggerLevel enum values).
  61. * (required) service name of type FIRLoggerService.
  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 FIRLoggerService.
  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. * FIRLogError(kFIRLoggerCore, @"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. #ifdef __cplusplus
  106. } // extern "C"
  107. #endif // __cplusplus
  108. @interface FIRLoggerWrapper : NSObject
  109. /**
  110. * Objective-C wrapper for FIRLogBasic to allow weak linking to FIRLogger
  111. * (required) log level (one of the FIRLoggerLevel enum values).
  112. * (required) service name of type FIRLoggerService.
  113. * (required) message code starting with "I-" which means iOS, followed by a capitalized
  114. * three-character service identifier and a six digit integer message ID that is unique
  115. * within the service.
  116. * An example of the message code is @"I-COR000001".
  117. * (required) message string which can be a format string.
  118. * (optional) variable arguments list obtained from calling va_start, used when message is a format
  119. * string.
  120. */
  121. + (void)logWithLevel:(FIRLoggerLevel)level
  122. withService:(FIRLoggerService)service
  123. withCode:(NSString *)messageCode
  124. withMessage:(NSString *)message
  125. withArgs:(va_list)args;
  126. @end
  127. NS_ASSUME_NONNULL_END