GDTCORConsoleLogger.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. // Set this to 1 to have the library print out as much as possible about what GDT is doing.
  18. #define GDT_VERBOSE_LOGGING 0
  19. /** A list of message codes to print in the logger that help to correspond printed messages with
  20. * code locations.
  21. *
  22. * Prefixes:
  23. * - MCW => MessageCodeWarning
  24. * - MCE => MessageCodeError
  25. */
  26. typedef NS_ENUM(NSInteger, GDTCORMessageCode) {
  27. /** For warning messages concerning transportBytes: not being implemented by a data object. */
  28. GDTCORMCWDataObjectMissingBytesImpl = 1,
  29. /** For warning messages concerning a failed event upload. */
  30. GDTCORMCWUploadFailed = 2,
  31. /** For warning messages concerning a forced event upload. */
  32. GDTCORMCWForcedUpload = 3,
  33. /** For warning messages concerning a failed reachability call. */
  34. GDTCORMCWReachabilityFailed = 4,
  35. /** For warning messages concerning a database warning. */
  36. GDTCORMCWDatabaseWarning = 5,
  37. /** For error messages concerning transform: not being implemented by an event transformer. */
  38. GDTCORMCETransformerDoesntImplementTransform = 1000,
  39. /** For error messages concerning the creation of a directory failing. */
  40. GDTCORMCEDirectoryCreationError = 1001,
  41. /** For error messages concerning the writing of a event file. */
  42. GDTCORMCEFileWriteError = 1002,
  43. /** For error messages concerning the lack of a prioritizer for a given backend. */
  44. GDTCORMCEPrioritizerError = 1003,
  45. /** For error messages concerning a package delivery API violation. */
  46. GDTCORMCEDeliverTwice = 1004,
  47. /** For error messages concerning an error in an implementation of -transportBytes. */
  48. GDTCORMCETransportBytesError = 1005,
  49. /** For general purpose error messages in a dependency. */
  50. GDTCORMCEGeneralError = 1006,
  51. /** For fatal errors. Please go to https://github.com/firebase/firebase-ios-sdk/issues and open
  52. * an issue if you encounter an error with this code.
  53. */
  54. GDTCORMCEFatalAssertion = 1007,
  55. /** For error messages concerning the reading of a event file. */
  56. GDTCORMCEFileReadError = 1008,
  57. /** For errors related to running sqlite. */
  58. GDTCORMCEDatabaseError = 1009,
  59. };
  60. /** Prints the given code and format string to the console.
  61. *
  62. * @param code The message code describing the nature of the log.
  63. * @param format The format string.
  64. */
  65. FOUNDATION_EXPORT
  66. void GDTCORLog(GDTCORMessageCode code, NSString *_Nonnull format, ...) NS_FORMAT_FUNCTION(2, 3);
  67. /** Prints an assert log to the console.
  68. *
  69. * @param wasFatal Send YES if the assertion should be fatal, NO otherwise.
  70. * @param file The file in which the failure occurred.
  71. * @param line The line number of the failure.
  72. * @param format The format string.
  73. */
  74. FOUNDATION_EXPORT void GDTCORLogAssert(BOOL wasFatal,
  75. NSString *_Nonnull file,
  76. NSInteger line,
  77. NSString *_Nullable format,
  78. ...) NS_FORMAT_FUNCTION(4, 5);
  79. /** Returns the string that represents some message code.
  80. *
  81. * @param code The code to convert to a string.
  82. * @return The string representing the message code.
  83. */
  84. FOUNDATION_EXPORT NSString *_Nonnull GDTCORMessageCodeEnumToString(GDTCORMessageCode code);
  85. // A define to wrap GULLogWarning with slightly more convenient usage.
  86. #define GDTCORLogWarning(MESSAGE_CODE, MESSAGE_FORMAT, ...) \
  87. GDTCORLog(MESSAGE_CODE, MESSAGE_FORMAT, __VA_ARGS__);
  88. // A define to wrap GULLogError with slightly more convenient usage and a failing assert.
  89. #define GDTCORLogError(MESSAGE_CODE, MESSAGE_FORMAT, ...) \
  90. GDTCORLog(MESSAGE_CODE, MESSAGE_FORMAT, __VA_ARGS__);
  91. // A define to wrap NSLog for verbose console logs only useful for local debugging.
  92. #if GDT_VERBOSE_LOGGING == 1
  93. #define GDTCORLogDebug(FORMAT, ...) NSLog(@"GDT: " FORMAT, __VA_ARGS__);
  94. #else
  95. #define GDTCORLogDebug(...)
  96. #endif // GDT_VERBOSE_LOGGING == 1