FDLLogging.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "DynamicLinks/Logging/FDLLogging.h"
  17. #ifdef GIN_SCION_LOGGING
  18. #import <FirebaseCore/FIRLogger.h>
  19. #endif // GIN_SCION_LOGGING
  20. #ifdef GIN_SCION_LOGGING
  21. #if __LP64__ // 64-bit
  22. NSString *const FDLMessageCodeIntegerFormat = @"%06ld";
  23. #else // 32-bit
  24. NSString *const FDLMessageCodeIntegerFormat = @"%06d";
  25. #endif // #if __LP64__
  26. NSString *FDLMessageCodeForLogIdentifier(FDLLogIdentifier identifer) {
  27. static NSString *const kMessageCodePrefix = @"I-FDL";
  28. NSString *intString = [NSString stringWithFormat:FDLMessageCodeIntegerFormat, identifer];
  29. return [kMessageCodePrefix stringByAppendingString:intString];
  30. }
  31. #endif // GIN_SCION_LOGGING
  32. void FDLLog(FDLLogLevel logLevel, FDLLogIdentifier identifer, NSString *message, ...) {
  33. va_list args_ptr;
  34. va_start(args_ptr, message);
  35. #ifdef GIN_SCION_LOGGING
  36. NSString *messageCode = FDLMessageCodeForLogIdentifier(identifer);
  37. switch (logLevel) {
  38. case FDLLogLevelError:
  39. FIRLogError(kFIRLoggerDynamicLinks, messageCode, message, args_ptr);
  40. break;
  41. case FDLLogLevelWarning:
  42. FIRLogWarning(kFIRLoggerDynamicLinks, messageCode, message, args_ptr);
  43. break;
  44. case FDLLogLevelNotice:
  45. FIRLogNotice(kFIRLoggerDynamicLinks, messageCode, message, args_ptr);
  46. break;
  47. case FDLLogLevelInfo:
  48. FIRLogInfo(kFIRLoggerDynamicLinks, messageCode, message, args_ptr);
  49. break;
  50. case FDLLogLevelDebug:
  51. FIRLogDebug(kFIRLoggerDynamicLinks, messageCode, message, args_ptr);
  52. break;
  53. }
  54. #else
  55. NSLogv(message, args_ptr);
  56. #endif // GIN_SCION_LOGGING
  57. va_end(args_ptr);
  58. }