UMCommonLogMacros.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // UMCommonLogMacros.h
  3. // testUMCommonLog
  4. //
  5. // Created by 张军华 on 2017/11/29.
  6. // Copyright © 2017年 张军华. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #define USing_CommonLog_Reflection
  10. #ifndef USing_CommonLog_Reflection
  11. #import "UMCommonLogConfig.h"
  12. /**
  13. * 根据等级打印日志
  14. * @param component 打印对应的组件 @see UMCommonComponent
  15. * @param logFlag 控制打印分级的枚举变量 @see UMCommonLogFlag
  16. * @param file 打印日志的文件
  17. * @param function 打印日志的函数
  18. * @param line 打印的日志的行数
  19. * @param format 需要打印的日志格式内容
  20. * @param ... 可变参数
  21. * @dicuss 本库不需要直接调用,可以用简易函数宏 @see UMCommonLogError,UMCommonLogWarn,UMCommonLogInfo,UMCommonLogDebug
  22. */
  23. FOUNDATION_EXPORT void UMCommonLog(UMCommonComponent component,UMCommonLogFlag logFlag,const char* file,const char* function,NSUInteger line,NSString *format, ...) NS_FORMAT_FUNCTION(6,7);
  24. //UMCommon的日志宏
  25. //简易函数类似于系统的NSLog函数,线程安全
  26. #define UMCommonLogError(format, ...) UMCommonLog(UMCommonComponent_UMCommon,UMCommonLogFlagError,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  27. #define UMCommonLogWarn(format, ...) UMCommonLog(UMCommonComponent_UMCommon,UMCommonLogFlagWarning,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  28. #define UMCommonLogInfo(format, ...) UMCommonLog(UMCommonComponent_UMCommon,UMCommonLogFlagInfo,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  29. #define UMCommonLogDebug(format, ...) UMCommonLog(UMCommonComponent_UMCommon,UMCommonLogFlagDebug,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  30. #define UMCommonLogVerbose(format, ...) UMCommonLog(UMCommonComponent_UMCommon,UMCommonLogFlagVerbose,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  31. //UMAnalytics的日志宏
  32. //简易函数类似于系统的NSLog函数,线程安全
  33. #define UMAnalyticsLogError(format, ...) UMCommonLog(UMCommonComponent_UMAnalytics,UMCommonLogFlagError,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  34. #define UMAnalyticsLogWarn(format, ...) UMCommonLog(UMCommonComponent_UMAnalytics,UMCommonLogFlagWarning,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  35. #define UMAnalyticsLogInfo(format, ...) UMCommonLog(UMCommonComponent_UMAnalytics,UMCommonLogFlagInfo,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  36. #define UMAnalyticsLogDebug(format, ...) UMCommonLog(UMCommonComponent_UMAnalytics,UMCommonLogFlagDebug,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  37. #define UMAnalyticsLogVerbose(format, ...) UMCommonLog(UMCommonComponent_UMAnalytics,UMCommonLogFlagVerbose,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  38. //UMPush 的日志宏
  39. //简易函数类似于系统的NSLog函数,线程安全
  40. #define UMPushLogError(format, ...) UMCommonLog(UMCommonComponent_UMPush,UMCommonLogFlagError,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  41. #define UMPushLogWarn(format, ...) UMCommonLog(UMCommonComponent_UMPush,UMCommonLogFlagWarning,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  42. #define UMPushLogInfo(format, ...) UMCommonLog(UMCommonComponent_UMPush,UMCommonLogFlagInfo,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  43. #define UMPushLogDebug(format, ...) UMCommonLog(UMCommonComponent_UMPush,UMCommonLogFlagDebug,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  44. #define UMPushLogVerbose(format, ...) UMCommonLog(UMCommonComponent_UMPush,UMCommonLogFlagVerbose,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  45. //UMShare 的日志宏
  46. //简易函数类似于系统的NSLog函数,线程安全
  47. #define UMShareLogError(format, ...) UMCommonLog(UMCommonComponent_UMShare,UMCommonLogFlagError,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  48. #define UMShareLogWarn(format, ...) UMCommonLog(UMCommonComponent_UMShare,UMCommonLogFlagWarning,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  49. #define UMShareLogInfo(format, ...) UMCommonLog(UMCommonComponent_UMShare,UMCommonLogFlagInfo,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  50. #define UMShareLogDebug(format, ...) UMCommonLog(UMCommonComponent_UMShare,UMCommonLogFlagDebug,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  51. #define UMShareLogVerbose(format, ...) UMCommonLog(UMCommonComponent_UMShare,UMCommonLogFlagVerbose,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  52. #else
  53. #define UMCommonLog UMCommonLog##UMShareSuffix
  54. #define UMCommonPrefixSubNameLog UMCommonPrefixSubNameLog##UMShareSuffix
  55. #define registerUMComponent registerUMComponent##UMShareSuffix
  56. #define setUMCommonComponentLevel setUMCommonComponentLevel##UMShareSuffix
  57. #define getUMCommonLogManager getUMCommonLogManager##UMShareSuffix
  58. #define getMetaUMCommonLogManager getMetaUMCommonLogManager##UMShareSuffix
  59. #define checkUMCommonLogManager checkUMCommonLogManager##UMShareSuffix
  60. #define checkValidUMCommonLogLevel checkValidUMCommonLogLevel##UMShareSuffix
  61. #define doUMCommonLog doUMCommonLog##UMShareSuffix
  62. #define doUMCommonPrefixSubNameLog doUMCommonPrefixSubNameLog##UMShareSuffix
  63. FOUNDATION_EXPORT BOOL registerUMComponent(NSInteger component,NSString* prefixName,NSString* componentVersion);
  64. FOUNDATION_EXPORT BOOL setUMCommonComponentLevel(NSInteger component,NSUInteger componentLevel);
  65. FOUNDATION_EXPORT void UMCommonLog(NSInteger component,NSInteger logFlag,const char* file,const char* function,NSUInteger line,NSString *format, ...) NS_FORMAT_FUNCTION(6,7);
  66. FOUNDATION_EXPORT void UMCommonPrefixSubNameLog(NSInteger component,NSInteger logFlag,const char* prefixSubName,const char* file,const char* function,NSUInteger line,NSString *format, ...) NS_FORMAT_FUNCTION(7,8);
  67. //获得UMCommonLog.bundle的国际化的字符串宏和对应的函数
  68. #define UMCommonLogTableNameForUMCommonUMShareSuffix @"UMSocialPromptLocalizable"
  69. #define UMCommonLogBundleNameForUMCommonUMShareSuffix @"UMCommonLog"
  70. #define UMCommonLogBundle UMCommonLogBundle##UMShareSuffix
  71. FOUNDATION_EXPORT NSBundle* UMCommonLogBundle();
  72. #define UMLocalizedStringForUMCommonSuffix(key) NSLocalizedStringWithDefaultValue(key,UMCommonLogTableNameForUMCommonUMShareSuffix,UMCommonLogBundle(), @"", nil)
  73. //UMCommon的日志宏
  74. //简易函数类似于系统的NSLog函数,线程安全
  75. #define UMCommonLogError(format, ...) UMCommonLog(1,1,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  76. #define UMCommonLogWarn(format, ...) UMCommonLog(1,2,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  77. #define UMCommonLogInfo(format, ...) UMCommonLog(1,4,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  78. #define UMCommonLogDebug(format, ...) UMCommonLog(1,8,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  79. #define UMCommonLogVerbose(format, ...) UMCommonLog(1,16,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  80. //UMCommon的分级日志宏
  81. #define UMCommonPrefixSubName ".Network"
  82. #define UMCommonPrefixSubNameLogError(format, ...) UMCommonPrefixSubNameLog(1,1,UMCommonPrefixSubName,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  83. #define UMCommonPrefixSubNameLogWarn(format, ...) UMCommonPrefixSubNameLog(1,2,UMCommonPrefixSubName,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  84. #define UMCommonPrefixSubNameLogInfo(format, ...) UMCommonPrefixSubNameLog(1,4,UMCommonPrefixSubName,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  85. #define UMCommonPrefixSubNameLogDebug(format, ...) UMCommonPrefixSubNameLog(1,8,UMCommonPrefixSubName,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  86. #define UMCommonPrefixSubNameLogVerbose(format, ...) UMCommonPrefixSubNameLog(1,16,UMCommonPrefixSubName,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  87. #define UMCommonPrefixSubName1 ".Core"
  88. #define UMCommonPrefixSubNameLogError1(format, ...) UMCommonPrefixSubNameLog(1,1,UMCommonPrefixSubName1,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  89. #define UMCommonPrefixSubNameLogWarn1(format, ...) UMCommonPrefixSubNameLog(1,2,UMCommonPrefixSubName1,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  90. #define UMCommonPrefixSubNameLogInfo1(format, ...) UMCommonPrefixSubNameLog(1,4,UMCommonPrefixSubName1,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  91. #define UMCommonPrefixSubNameLogDebug1(format, ...) UMCommonPrefixSubNameLog(1,8,UMCommonPrefixSubName1,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  92. #define UMCommonPrefixSubNameLogVerbose1(format, ...) UMCommonPrefixSubNameLog(1,16,UMCommonPrefixSubName1,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  93. #define UMCommonPrefixSubNameLogError2(UMCommonPrefixSubName2,format, ...) UMCommonPrefixSubNameLog(1,1,UMCommonPrefixSubName2,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  94. #define UMCommonPrefixSubNameLogWarn2(UMCommonPrefixSubName2,format, ...) UMCommonPrefixSubNameLog(1,2,UMCommonPrefixSubName2,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  95. #define UMCommonPrefixSubNameLogInfo2(UMCommonPrefixSubName2,format, ...) UMCommonPrefixSubNameLog(1,4,UMCommonPrefixSubName2,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  96. #define UMCommonPrefixSubNameLogDebug2(UMCommonPrefixSubName2,format, ...) UMCommonPrefixSubNameLog(1,8,UMCommonPrefixSubName2,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  97. #define UMCommonPrefixSubNameLogVerbose2(UMCommonPrefixSubName2,format, ...) UMCommonPrefixSubNameLog(1,16,UMCommonPrefixSubName2,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  98. //UMAnalytics的日志宏
  99. //简易函数类似于系统的NSLog函数,线程安全
  100. #define UMAnalyticsLogError(format, ...) UMCommonLog(2,1,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  101. #define UMAnalyticsLogWarn(format, ...) UMCommonLog(2,2,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  102. #define UMAnalyticsLogInfo(format, ...) UMCommonLog(2,4,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  103. #define UMAnalyticsLogDebug(format, ...) UMCommonLog(2,8,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  104. #define UMAnalyticsLogVerbose(format, ...) UMCommonLog(2,16,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  105. //UMPush 的日志宏
  106. //简易函数类似于系统的NSLog函数,线程安全
  107. #define UMPushLogError(format, ...) UMCommonLog(3,1,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  108. #define UMPushLogWarn(format, ...) UMCommonLog(3,2,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  109. #define UMPushLogInfo(format, ...) UMCommonLog(3,4,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  110. #define UMPushLogDebug(format, ...) UMCommonLog(3,8,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  111. #define UMPushLogVerbose(format, ...) UMCommonLog(3,16,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  112. //UMShare 的日志宏
  113. //简易函数类似于系统的NSLog函数,线程安全
  114. #define UMShareLogError(format, ...) UMCommonLog(4,1,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  115. #define UMShareLogWarn(format, ...) UMCommonLog(4,2,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  116. #define UMShareLogInfo(format, ...) UMCommonLog(4,4,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  117. #define UMShareLogDebug(format, ...) UMCommonLog(4,8,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  118. #define UMShareLogVerbose(format, ...) UMCommonLog(4,16,__FILE__,__PRETTY_FUNCTION__,__LINE__,format,##__VA_ARGS__)
  119. #endif