GDTCORConsoleLogger.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 error messages concerning transform: not being implemented by an event transformer. */
  36. GDTCORMCETransformerDoesntImplementTransform = 1000,
  37. /** For error messages concerning the creation of a directory failing. */
  38. GDTCORMCEDirectoryCreationError = 1001,
  39. /** For error messages concerning the writing of a event file. */
  40. GDTCORMCEFileWriteError = 1002,
  41. /** For error messages concerning the lack of a prioritizer for a given backend. */
  42. GDTCORMCEPrioritizerError = 1003,
  43. /** For error messages concerning a package delivery API violation. */
  44. GDTCORMCEDeliverTwice = 1004,
  45. /** For error messages concerning an error in an implementation of -transportBytes. */
  46. GDTCORMCETransportBytesError = 1005,
  47. /** For general purpose error messages in a dependency. */
  48. GDTCORMCEGeneralError = 1006,
  49. /** For fatal errors. Please go to https://github.com/firebase/firebase-ios-sdk/issues and open
  50. * an issue if you encounter an error with this code.
  51. */
  52. GDTCORMCEFatalAssertion = 1007,
  53. /** For error messages concerning the reading of a event file. */
  54. GDTCORMCEFileReadError = 1008
  55. };
  56. /** Prints the given code and format string to the console.
  57. *
  58. * @param code The message code describing the nature of the log.
  59. * @param format The format string.
  60. */
  61. FOUNDATION_EXPORT
  62. void GDTCORLog(GDTCORMessageCode code, NSString *_Nonnull format, ...) NS_FORMAT_FUNCTION(2, 3);
  63. /** Prints an assert log to the console.
  64. *
  65. * @param wasFatal Send YES if the assertion should be fatal, NO otherwise.
  66. * @param file The file in which the failure occurred.
  67. * @param line The line number of the failure.
  68. * @param format The format string.
  69. */
  70. FOUNDATION_EXPORT void GDTCORLogAssert(BOOL wasFatal,
  71. NSString *_Nonnull file,
  72. NSInteger line,
  73. NSString *_Nullable format,
  74. ...) NS_FORMAT_FUNCTION(4, 5);
  75. /** Returns the string that represents some message code.
  76. *
  77. * @param code The code to convert to a string.
  78. * @return The string representing the message code.
  79. */
  80. FOUNDATION_EXPORT NSString *_Nonnull GDTCORMessageCodeEnumToString(GDTCORMessageCode code);
  81. // A define to wrap GULLogWarning with slightly more convenient usage.
  82. #define GDTCORLogWarning(MESSAGE_CODE, MESSAGE_FORMAT, ...) \
  83. GDTCORLog(MESSAGE_CODE, MESSAGE_FORMAT, __VA_ARGS__);
  84. // A define to wrap GULLogError with slightly more convenient usage and a failing assert.
  85. #define GDTCORLogError(MESSAGE_CODE, MESSAGE_FORMAT, ...) \
  86. GDTCORLog(MESSAGE_CODE, MESSAGE_FORMAT, __VA_ARGS__);
  87. // A define to wrap NSLog for verbose console logs only useful for local debugging.
  88. #if GDT_VERBOSE_LOGGING == 1
  89. #define GDTCORLogDebug(FORMAT, ...) NSLog(@"GDT: " FORMAT, __VA_ARGS__);
  90. #else
  91. #define GDTCORLogDebug(...)
  92. #endif // GDT_VERBOSE_LOGGING == 1