FBDebugLogDelegateDecorator.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import "FBDebugLogDelegateDecorator.h"
  10. #import "FBLogger.h"
  11. #import "XCTestPrivateSymbols.h"
  12. @interface FBDebugLogDelegateDecorator ()
  13. @property (nonatomic, strong) id<XCDebugLogDelegate> debugLogger;
  14. @end
  15. @implementation FBDebugLogDelegateDecorator
  16. + (void)decorateXCTestLogger
  17. {
  18. FBDebugLogDelegateDecorator *decorator = [FBDebugLogDelegateDecorator new];
  19. id<XCDebugLogDelegate> debugLogger = XCDebugLogger();
  20. if ([debugLogger isKindOfClass:FBDebugLogDelegateDecorator.class]) {
  21. // Already decorated
  22. return;
  23. }
  24. decorator.debugLogger = debugLogger;
  25. XCSetDebugLogger(decorator);
  26. }
  27. - (void)logDebugMessage:(NSString *)logEntry
  28. {
  29. NSString *debugLogEntry = logEntry;
  30. static NSString *processName;
  31. static dispatch_once_t onceToken;
  32. dispatch_once(&onceToken, ^{
  33. processName = [NSProcessInfo processInfo].processName;
  34. });
  35. if ([logEntry rangeOfString:[NSString stringWithFormat:@" %@[", processName]].location != NSNotFound) {
  36. // Ignoring "13:37:07.638 TestingApp[56374:10997466] " from log entry
  37. NSUInteger ignoreCharCount = [logEntry rangeOfString:@"]"].location + 2;
  38. debugLogEntry = [logEntry substringWithRange:NSMakeRange(ignoreCharCount, logEntry.length - ignoreCharCount)];
  39. }
  40. [FBLogger verboseLog:debugLogEntry];
  41. [self.debugLogger logDebugMessage:logEntry];
  42. }
  43. @end