GULLogger.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. * Changes the default logging level of GULLoggerLevelNotice to a user-specified level.
  40. * The default level cannot be set above GULLoggerLevelNotice if the app is running from App Store.
  41. * (required) log level (one of the GULLoggerLevel enum values).
  42. */
  43. extern void GULSetLoggerLevel(GULLoggerLevel loggerLevel);
  44. /**
  45. * Checks if the specified logger level is loggable given the current settings.
  46. * (required) log level (one of the GULLoggerLevel enum values).
  47. */
  48. extern BOOL GULIsLoggableLevel(GULLoggerLevel loggerLevel);
  49. /**
  50. * Register version to include in logs.
  51. * (required) version
  52. */
  53. extern void GULLoggerRegisterVersion(NSString *version);
  54. /**
  55. * Logs a message to the Xcode console and the device log. If running from AppStore, will
  56. * not log any messages with a level higher than GULLoggerLevelNotice to avoid log spamming.
  57. * (required) log level (one of the GULLoggerLevel enum values).
  58. * (required) service name of type GULLoggerService.
  59. * (required) message code starting with "I-" which means iOS, followed by a capitalized
  60. * three-character service identifier and a six digit integer message ID that is unique
  61. * within the service.
  62. * An example of the message code is @"I-COR000001".
  63. * (required) message string which can be a format string.
  64. * (optional) variable arguments list obtained from calling va_start, used when message is a format
  65. * string.
  66. */
  67. extern void GULLogBasic(GULLoggerLevel level,
  68. GULLoggerService service,
  69. BOOL forceLog,
  70. NSString *messageCode,
  71. NSString *message,
  72. // On 64-bit simulators, va_list is not a pointer, so cannot be marked nullable
  73. // See: http://stackoverflow.com/q/29095469
  74. #if __LP64__ && TARGET_OS_SIMULATOR || TARGET_OS_OSX
  75. va_list args_ptr
  76. #else
  77. va_list _Nullable args_ptr
  78. #endif
  79. );
  80. /**
  81. * The following functions accept the following parameters in order:
  82. * (required) service name of type GULLoggerService.
  83. * (required) message code starting from "I-" which means iOS, followed by a capitalized
  84. * three-character service identifier and a six digit integer message ID that is unique
  85. * within the service.
  86. * An example of the message code is @"I-COR000001".
  87. * See go/firebase-log-proposal for details.
  88. * (required) message string which can be a format string.
  89. * (optional) the list of arguments to substitute into the format string.
  90. * Example usage:
  91. * GULLogError(kGULLoggerCore, @"I-COR000001", @"Configuration of %@ failed.", app.name);
  92. */
  93. extern void GULLogError(GULLoggerService service,
  94. BOOL force,
  95. NSString *messageCode,
  96. NSString *message,
  97. ...) NS_FORMAT_FUNCTION(4, 5);
  98. extern void GULLogWarning(GULLoggerService service,
  99. BOOL force,
  100. NSString *messageCode,
  101. NSString *message,
  102. ...) NS_FORMAT_FUNCTION(4, 5);
  103. extern void GULLogNotice(GULLoggerService service,
  104. BOOL force,
  105. NSString *messageCode,
  106. NSString *message,
  107. ...) NS_FORMAT_FUNCTION(4, 5);
  108. extern void GULLogInfo(GULLoggerService service,
  109. BOOL force,
  110. NSString *messageCode,
  111. NSString *message,
  112. ...) NS_FORMAT_FUNCTION(4, 5);
  113. extern void GULLogDebug(GULLoggerService service,
  114. BOOL force,
  115. NSString *messageCode,
  116. NSString *message,
  117. ...) NS_FORMAT_FUNCTION(4, 5);
  118. #ifdef __cplusplus
  119. } // extern "C"
  120. #endif // __cplusplus
  121. @interface GULLoggerWrapper : NSObject
  122. /**
  123. * Objective-C wrapper for GULLogBasic to allow weak linking to GULLogger
  124. * (required) log level (one of the GULLoggerLevel enum values).
  125. * (required) service name of type GULLoggerService.
  126. * (required) message code starting with "I-" which means iOS, followed by a capitalized
  127. * three-character service identifier and a six digit integer message ID that is unique
  128. * within the service.
  129. * An example of the message code is @"I-COR000001".
  130. * (required) message string which can be a format string.
  131. * (optional) variable arguments list obtained from calling va_start, used when message is a format
  132. * string.
  133. */
  134. + (void)logWithLevel:(GULLoggerLevel)level
  135. withService:(GULLoggerService)service
  136. withCode:(NSString *)messageCode
  137. withMessage:(NSString *)message
  138. withArgs:(va_list)args;
  139. @end
  140. NS_ASSUME_NONNULL_END