GDTCORConsoleLogger.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. /** The current logging level. This value and higher will be printed. Declared as volatile to make
  18. * getting and setting atomic.
  19. */
  20. FOUNDATION_EXPORT volatile NSInteger GDTCORConsoleLoggerLoggingLevel;
  21. /** A list of logging levels that GDT supports. */
  22. typedef NS_ENUM(NSInteger, GDTCORLoggingLevel) {
  23. /** Causes all logs to be printed. */
  24. GDTCORLoggingLevelDebug = 1,
  25. /** Causes all non-debug logs to be printed. */
  26. GDTCORLoggingLevelVerbose = 2,
  27. /** Causes warnings and errors to be printed. */
  28. GDTCORLoggingLevelWarnings = 3,
  29. /** Causes errors to be printed. This is the default value. */
  30. GDTCORLoggingLevelErrors = 4
  31. };
  32. /** A list of message codes to print in the logger that help to correspond printed messages with
  33. * code locations.
  34. *
  35. * Prefixes:
  36. * - MCD => MessageCodeDebug
  37. * - MCW => MessageCodeWarning
  38. * - MCE => MessageCodeError
  39. */
  40. typedef NS_ENUM(NSInteger, GDTCORMessageCode) {
  41. /** For debug logs. */
  42. GDTCORMCDDebugLog = 0,
  43. /** For warning messages concerning transportBytes: not being implemented by a data object. */
  44. GDTCORMCWDataObjectMissingBytesImpl = 1,
  45. /** For warning messages concerning a failed event upload. */
  46. GDTCORMCWUploadFailed = 2,
  47. /** For warning messages concerning a forced event upload. */
  48. GDTCORMCWForcedUpload = 3,
  49. /** For warning messages concerning a failed reachability call. */
  50. GDTCORMCWReachabilityFailed = 4,
  51. /** For warning messages concerning a database warning. */
  52. GDTCORMCWDatabaseWarning = 5,
  53. /** For warning messages concerning the reading of a event file. */
  54. GDTCORMCWFileReadError = 6,
  55. /** For error messages concerning transform: not being implemented by an event transformer. */
  56. GDTCORMCETransformerDoesntImplementTransform = 1000,
  57. /** For error messages concerning the creation of a directory failing. */
  58. GDTCORMCEDirectoryCreationError = 1001,
  59. /** For error messages concerning the writing of a event file. */
  60. GDTCORMCEFileWriteError = 1002,
  61. /** For error messages concerning the lack of a prioritizer for a given backend. */
  62. GDTCORMCEPrioritizerError = 1003,
  63. /** For error messages concerning a package delivery API violation. */
  64. GDTCORMCEDeliverTwice = 1004,
  65. /** For error messages concerning an error in an implementation of -transportBytes. */
  66. GDTCORMCETransportBytesError = 1005,
  67. /** For general purpose error messages in a dependency. */
  68. GDTCORMCEGeneralError = 1006,
  69. /** For fatal errors. Please go to https://github.com/firebase/firebase-ios-sdk/issues and open
  70. * an issue if you encounter an error with this code.
  71. */
  72. GDTCORMCEFatalAssertion = 1007,
  73. /** For error messages concerning the reading of a event file. */
  74. GDTCORMCEFileReadError = 1008,
  75. /** For errors related to running sqlite. */
  76. GDTCORMCEDatabaseError = 1009,
  77. };
  78. /** Prints the given code and format string to the console.
  79. *
  80. * @param code The message code describing the nature of the log.
  81. * @param logLevel The log level of this log.
  82. * @param format The format string.
  83. */
  84. FOUNDATION_EXPORT
  85. void GDTCORLog(GDTCORMessageCode code, GDTCORLoggingLevel logLevel, NSString *_Nonnull format, ...)
  86. NS_FORMAT_FUNCTION(3, 4);
  87. /** Prints an assert log to the console.
  88. *
  89. * @param wasFatal Send YES if the assertion should be fatal, NO otherwise.
  90. * @param file The file in which the failure occurred.
  91. * @param line The line number of the failure.
  92. * @param format The format string.
  93. */
  94. FOUNDATION_EXPORT void GDTCORLogAssert(BOOL wasFatal,
  95. NSString *_Nonnull file,
  96. NSInteger line,
  97. NSString *_Nullable format,
  98. ...) NS_FORMAT_FUNCTION(4, 5);
  99. /** Returns the string that represents some message code.
  100. *
  101. * @param code The code to convert to a string.
  102. * @return The string representing the message code.
  103. */
  104. FOUNDATION_EXPORT NSString *_Nonnull GDTCORMessageCodeEnumToString(GDTCORMessageCode code);
  105. #define GDTCORLogDebug(MESSAGE_FORMAT, ...) \
  106. GDTCORLog(GDTCORMCDDebugLog, GDTCORLoggingLevelDebug, MESSAGE_FORMAT, __VA_ARGS__);
  107. // A define to wrap GULLogWarning with slightly more convenient usage.
  108. #define GDTCORLogWarning(MESSAGE_CODE, MESSAGE_FORMAT, ...) \
  109. GDTCORLog(MESSAGE_CODE, GDTCORLoggingLevelWarnings, MESSAGE_FORMAT, __VA_ARGS__);
  110. // A define to wrap GULLogError with slightly more convenient usage and a failing assert.
  111. #define GDTCORLogError(MESSAGE_CODE, MESSAGE_FORMAT, ...) \
  112. GDTCORLog(MESSAGE_CODE, GDTCORLoggingLevelErrors, MESSAGE_FORMAT, __VA_ARGS__);