GULLogger.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright 2018 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 "GULLoggerLevel.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. /**
  20. * The services used in the logger.
  21. */
  22. typedef NSString *const GULLoggerService;
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif // __cplusplus
  26. /**
  27. * Initialize GULLogger.
  28. */
  29. extern void GULLoggerInitializeASL(void);
  30. /**
  31. * Override log level to Debug.
  32. */
  33. void GULLoggerForceDebug(void);
  34. /**
  35. * Turn on logging to STDERR.
  36. */
  37. extern void GULLoggerEnableSTDERR(void);
  38. /**
  39. * Gets the current GULLoggerLevel.
  40. */
  41. extern GULLoggerLevel GULGetLoggerLevel(void);
  42. /**
  43. * Changes the default logging level of GULLoggerLevelNotice to a user-specified level.
  44. * The default level cannot be set above GULLoggerLevelNotice if the app is running from App Store.
  45. * (required) log level (one of the GULLoggerLevel enum values).
  46. */
  47. extern void GULSetLoggerLevel(GULLoggerLevel loggerLevel);
  48. /**
  49. * Checks if the specified logger level is loggable given the current settings.
  50. * (required) log level (one of the GULLoggerLevel enum values).
  51. */
  52. extern BOOL GULIsLoggableLevel(GULLoggerLevel loggerLevel);
  53. /**
  54. * Register version to include in logs.
  55. * (required) version
  56. */
  57. extern void GULLoggerRegisterVersion(NSString *version);
  58. /**
  59. * Logs a message to the Xcode console and the device log. If running from AppStore, will
  60. * not log any messages with a level higher than GULLoggerLevelNotice to avoid log spamming.
  61. * (required) log level (one of the GULLoggerLevel enum values).
  62. * (required) service name of type GULLoggerService.
  63. * (required) message code starting with "I-" which means iOS, followed by a capitalized
  64. * three-character service identifier and a six digit integer message ID that is unique
  65. * within the service.
  66. * An example of the message code is @"I-COR000001".
  67. * (required) message string which can be a format string.
  68. * (optional) variable arguments list obtained from calling va_start, used when message is a format
  69. * string.
  70. */
  71. extern void GULLogBasic(GULLoggerLevel level,
  72. GULLoggerService service,
  73. BOOL forceLog,
  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 GULLoggerService.
  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. * GULLogError(kGULLoggerCore, @"I-COR000001", @"Configuration of %@ failed.", app.name);
  96. */
  97. extern void GULLogError(GULLoggerService service,
  98. BOOL force,
  99. NSString *messageCode,
  100. NSString *message,
  101. ...) NS_FORMAT_FUNCTION(4, 5);
  102. extern void GULLogWarning(GULLoggerService service,
  103. BOOL force,
  104. NSString *messageCode,
  105. NSString *message,
  106. ...) NS_FORMAT_FUNCTION(4, 5);
  107. extern void GULLogNotice(GULLoggerService service,
  108. BOOL force,
  109. NSString *messageCode,
  110. NSString *message,
  111. ...) NS_FORMAT_FUNCTION(4, 5);
  112. extern void GULLogInfo(GULLoggerService service,
  113. BOOL force,
  114. NSString *messageCode,
  115. NSString *message,
  116. ...) NS_FORMAT_FUNCTION(4, 5);
  117. extern void GULLogDebug(GULLoggerService service,
  118. BOOL force,
  119. NSString *messageCode,
  120. NSString *message,
  121. ...) NS_FORMAT_FUNCTION(4, 5);
  122. #ifdef __cplusplus
  123. } // extern "C"
  124. #endif // __cplusplus
  125. @interface GULLoggerWrapper : NSObject
  126. /**
  127. * Objective-C wrapper for GULLogBasic to allow weak linking to GULLogger
  128. * (required) log level (one of the GULLoggerLevel enum values).
  129. * (required) service name of type GULLoggerService.
  130. * (required) message code starting with "I-" which means iOS, followed by a capitalized
  131. * three-character service identifier and a six digit integer message ID that is unique
  132. * within the service.
  133. * An example of the message code is @"I-COR000001".
  134. * (required) message string which can be a format string.
  135. * (optional) variable arguments list obtained from calling va_start, used when message is a format
  136. * string.
  137. */
  138. + (void)logWithLevel:(GULLoggerLevel)level
  139. withService:(GULLoggerService)service
  140. withCode:(NSString *)messageCode
  141. withMessage:(NSString *)message
  142. withArgs:(va_list)args;
  143. @end
  144. NS_ASSUME_NONNULL_END