WXLog.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. #import <Foundation/Foundation.h>
  20. #define WXLogLevel WeexLogLevel
  21. typedef NS_ENUM(NSInteger, WXLogFlag) {
  22. WXLogFlagError = 1 << 0,
  23. WXLogFlagWarning = 1 << 1,
  24. WXLogFlagInfo = 1 << 2,
  25. WXLogFlagLog = 1 << 3,
  26. WXLogFlagDebug = 1 << 4
  27. };
  28. /**
  29. * Use Log levels to filter logs.
  30. */
  31. typedef NS_ENUM(NSUInteger, WeexLogLevel){
  32. /**
  33. * No logs
  34. */
  35. WXLogLevelOff = 0,
  36. /**
  37. * Error only
  38. */
  39. WXLogLevelError = WXLogFlagError,
  40. /**
  41. * Error and warning
  42. */
  43. WXLogLevelWarning = WXLogLevelError | WXLogFlagWarning,
  44. /**
  45. * Error, warning and info
  46. */
  47. WXLogLevelInfo = WXLogLevelWarning | WXLogFlagInfo,
  48. /**
  49. * Log, warning info
  50. */
  51. WXLogLevelLog = WXLogFlagLog | WXLogLevelInfo,
  52. /**
  53. * Error, warning, info and debug logs
  54. */
  55. WXLogLevelDebug = WXLogLevelLog | WXLogFlagDebug,
  56. /**
  57. * All
  58. */
  59. WXLogLevelAll = NSUIntegerMax
  60. };
  61. /**
  62. * External log protocol, which is used to output the log to the external.
  63. */
  64. @protocol WXLogProtocol <NSObject>
  65. @required
  66. /**
  67. * External log level.
  68. */
  69. - (WXLogLevel)logLevel;
  70. - (void)log:(WXLogFlag)flag message:(NSString *)message;
  71. @end
  72. @interface WXLog : NSObject
  73. + (WXLogLevel)logLevel;
  74. + (void)setLogLevel:(WXLogLevel)level;
  75. + (NSString *)logLevelString;
  76. + (void)setLogLevelString:(NSString *)levelString;
  77. //+ (void)log:(WXLogFlag)flag file:(const char *)fileName line:(NSUInteger)line format:(NSString *)format, ... NS_FORMAT_FUNCTION(4,5);
  78. + (void)log:(WXLogFlag)flag file:(const char *)fileName line:(NSUInteger)line message:(NSString *)message;
  79. + (void)devLog:(WXLogFlag)flag file:(const char *)fileName line:(NSUInteger)line format:(NSString *)format, ... NS_FORMAT_FUNCTION(4,5);
  80. + (void)registerExternalLog:(id<WXLogProtocol>)externalLog;
  81. @end
  82. #define WX_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
  83. #define WX_LOG(flag, fmt, ...) \
  84. do { \
  85. [WXLog devLog:flag \
  86. file:WX_FILENAME \
  87. line:__LINE__ \
  88. format:(fmt), ## __VA_ARGS__]; \
  89. } while(0)
  90. extern void _WXLogObjectsImpl(NSString *severity, NSArray *arguments);
  91. #define WXLog(format,...) WX_LOG(WXLogFlagLog, format, ##__VA_ARGS__)
  92. #define WXLogDebug(format, ...) WX_LOG(WXLogFlagDebug, format, ##__VA_ARGS__)
  93. #define WXLogInfo(format, ...) WX_LOG(WXLogFlagInfo, format, ##__VA_ARGS__)
  94. #define WXLogWarning(format, ...) WX_LOG(WXLogFlagWarning, format ,##__VA_ARGS__)
  95. #define WXLogError(format, ...) WX_LOG(WXLogFlagError, format, ##__VA_ARGS__)