Нет описания

AWSLogging.m 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  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. // A copy of the License is located at
  7. //
  8. // http://aws.amazon.com/apache2.0
  9. //
  10. // or in the "license" file accompanying this file. This file is distributed
  11. // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. // express or implied. See the License for the specific language governing
  13. // permissions and limitations under the License.
  14. //
  15. #import "AWSLogging.h"
  16. #import "AWSService.h"
  17. #pragma clang diagnostic push
  18. #pragma clang diagnostic ignored "-Wdeprecated-implementations"
  19. @implementation AWSLogger
  20. - (instancetype)init {
  21. if (self = [super init]) {
  22. _logLevel = AWSLogLevelDebug;
  23. }
  24. return self;
  25. }
  26. + (instancetype)defaultLogger {
  27. static AWSLogger *_defaultLogger = nil;
  28. static dispatch_once_t onceToken;
  29. dispatch_once(&onceToken, ^{
  30. _defaultLogger = [AWSLogger new];
  31. });
  32. return _defaultLogger;
  33. }
  34. - (void)log:(AWSLogLevel)logLevel format:(NSString *)fmt, ... NS_FORMAT_FUNCTION(2, 3) {
  35. if(self.logLevel >= logLevel) {
  36. va_list args;
  37. va_start(args, fmt);
  38. NSLog(@"AWSiOSSDK v%@ [%@] %@", AWSiOSSDKVersion, [self logLevelLabel:logLevel], [[NSString alloc] initWithFormat:fmt arguments:args]);
  39. va_end(args);
  40. }
  41. }
  42. - (NSString *)logLevelLabel:(AWSLogLevel)logLevel {
  43. switch (logLevel) {
  44. case AWSLogLevelError:
  45. return @"Error";
  46. case AWSLogLevelWarn:
  47. return @"Warn";
  48. case AWSLogLevelInfo:
  49. return @"Info";
  50. case AWSLogLevelDebug:
  51. return @"Debug";
  52. case AWSLogLevelVerbose:
  53. return @"Verbose";
  54. case AWSLogLevelUnknown:
  55. case AWSLogLevelNone:
  56. default:
  57. return @"?";
  58. }
  59. }
  60. @end
  61. #pragma clang diagnostic pop