GDTCORConsoleLogger.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 "GDTCORLibrary/Public/GDTCORConsoleLogger.h"
  17. /** The console logger prefix. */
  18. static NSString *kGDTCORConsoleLogger = @"[GoogleDataTransport]";
  19. NSString *GDTCORMessageCodeEnumToString(GDTCORMessageCode code) {
  20. return [[NSString alloc] initWithFormat:@"I-GDTCOR%06ld", (long)code];
  21. }
  22. void GDTCORLog(GDTCORMessageCode code, NSString *format, ...) {
  23. // Don't log anything in not debug builds.
  24. #if !NDEBUG
  25. NSString *logFormat = [NSString stringWithFormat:@"%@[%@] %@", kGDTCORConsoleLogger,
  26. GDTCORMessageCodeEnumToString(code), format];
  27. va_list args;
  28. va_start(args, format);
  29. NSLogv(logFormat, args);
  30. va_end(args);
  31. #endif // !NDEBUG
  32. }
  33. void GDTCORLogAssert(
  34. BOOL wasFatal, NSString *_Nonnull file, NSInteger line, NSString *_Nullable format, ...) {
  35. GDTCORMessageCode code = wasFatal ? GDTCORMCEFatalAssertion : GDTCORMCEGeneralError;
  36. // Don't log anything in not debug builds.
  37. #if !NDEBUG
  38. NSString *logFormat =
  39. [NSString stringWithFormat:@"%@[%@] (%@:%ld) : %@", kGDTCORConsoleLogger,
  40. GDTCORMessageCodeEnumToString(code), file, (long)line, format];
  41. va_list args;
  42. va_start(args, format);
  43. NSLogv(logFormat, args);
  44. va_end(args);
  45. #endif // !NDEBUG
  46. }