UTMLogging.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // Copyright © 2020 osy. 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. // 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 "UTMLogging.h"
  17. #if !defined(WITH_REMOTE)
  18. @import QEMUKitInternal;
  19. #endif
  20. static UTMLogging *gLoggingInstance;
  21. void UTMLog(NSString *format, ...) {
  22. va_list args;
  23. va_start(args, format);
  24. NSString *line = [[NSString alloc] initWithFormat:[format stringByAppendingString:@"\n"] arguments:args];
  25. va_end(args);
  26. [[UTMLogging sharedInstance] writeLine:line];
  27. }
  28. @implementation UTMLogging
  29. + (void)initialize {
  30. static BOOL initialized = NO;
  31. if (!initialized) {
  32. initialized = YES;
  33. gLoggingInstance = [[UTMLogging alloc] init];
  34. }
  35. }
  36. + (UTMLogging *)sharedInstance {
  37. return gLoggingInstance;
  38. }
  39. - (void)writeLine:(NSString *)line {
  40. #if defined(WITH_REMOTE)
  41. NSLog(@"%@", line);
  42. #else
  43. [QEMULogging.sharedInstance writeLine:line];
  44. #endif
  45. }
  46. @end