No Description

AWSDDOSLogger.m 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Software License Agreement (BSD License)
  2. //
  3. // Copyright (c) 2010-2016, Deusty, LLC
  4. // All rights reserved.
  5. //
  6. // Redistribution and use of this software in source and binary forms,
  7. // with or without modification, are permitted provided that the following conditions are met:
  8. //
  9. // * Redistributions of source code must retain the above copyright notice,
  10. // this list of conditions and the following disclaimer.
  11. //
  12. // * Neither the name of Deusty nor the names of its contributors may be used
  13. // to endorse or promote products derived from this software without specific
  14. // prior written permission of Deusty, LLC.
  15. #import "AWSDDOSLogger.h"
  16. #import <os/log.h>
  17. @implementation AWSDDOSLogger
  18. static AWSDDOSLogger *sharedInstance;
  19. + (instancetype)sharedInstance {
  20. static dispatch_once_t AWSDDOSLoggerOnceToken;
  21. dispatch_once(&AWSDDOSLoggerOnceToken, ^{
  22. sharedInstance = [[[self class] alloc] init];
  23. });
  24. return sharedInstance;
  25. }
  26. - (instancetype)init {
  27. if (sharedInstance != nil) {
  28. return nil;
  29. }
  30. if (self = [super init]) {
  31. return self;
  32. }
  33. return nil;
  34. }
  35. - (void)logMessage:(AWSDDLogMessage *)logMessage {
  36. // Skip captured log messages
  37. if ([logMessage->_fileName isEqualToString:@"AWSDDASLLogCapture"]) {
  38. return;
  39. }
  40. NSString * message = _logFormatter ? [_logFormatter formatLogMessage:logMessage] : logMessage->_message;
  41. if (message) {
  42. const char *msg = [message UTF8String];
  43. switch (logMessage->_flag) {
  44. case AWSDDLogFlagError :
  45. os_log_error(OS_LOG_DEFAULT, "%{public}s", msg);
  46. break;
  47. case AWSDDLogFlagWarning :
  48. case AWSDDLogFlagInfo :
  49. os_log_info(OS_LOG_DEFAULT, "%{public}s", msg);
  50. break;
  51. case AWSDDLogFlagDebug :
  52. case AWSDDLogFlagVerbose :
  53. default :
  54. os_log_debug(OS_LOG_DEFAULT, "%{public}s", msg);
  55. break;
  56. }
  57. }
  58. }
  59. - (NSString *)loggerName {
  60. return @"cocoa.lumberjack.osLogger";
  61. }
  62. @end