No Description

AWSDDLogMacros.h 5.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // Disable legacy macros
  16. #ifndef AWSDD_LEGACY_MACROS
  17. #define AWSDD_LEGACY_MACROS 0
  18. #endif
  19. #import "AWSDDLog.h"
  20. /**
  21. * Whether async should be used by log messages, excluding error messages that are always sent sync.
  22. **/
  23. #ifndef AWSDD_LOG_ASYNC_ENABLED
  24. #define AWSDD_LOG_ASYNC_ENABLED YES
  25. #endif
  26. /**
  27. * These are the two macros that all other macros below compile into.
  28. * These big multiline macros makes all the other macros easier to read.
  29. **/
  30. #define AWSDD_LOG_MACRO(isAsynchronous, lvl, flg, ctx, atag, fnct, frmt, ...) \
  31. [AWSDDLog log : isAsynchronous \
  32. level : lvl \
  33. flag : flg \
  34. context : ctx \
  35. file : __FILE__ \
  36. function : fnct \
  37. line : __LINE__ \
  38. tag : atag \
  39. format : (frmt), ## __VA_ARGS__]
  40. #define LOG_MACRO_TO_AWSDDLOG(ddlog, isAsynchronous, lvl, flg, ctx, atag, fnct, frmt, ...) \
  41. [ddlog log : isAsynchronous \
  42. level : lvl \
  43. flag : flg \
  44. context : ctx \
  45. file : __FILE__ \
  46. function : fnct \
  47. line : __LINE__ \
  48. tag : atag \
  49. format : (frmt), ## __VA_ARGS__]
  50. /**
  51. * Define version of the macro that only execute if the log level is above the threshold.
  52. * The compiled versions essentially look like this:
  53. *
  54. * if (logFlagForThisLogMsg & ddLogLevel) { execute log message }
  55. *
  56. * When LOG_LEVEL_DEF is defined as ddLogLevel.
  57. *
  58. * As shown further below, Lumberjack actually uses a bitmask as opposed to primitive log levels.
  59. * This allows for a great amount of flexibility and some pretty advanced fine grained logging techniques.
  60. *
  61. * Note that when compiler optimizations are enabled (as they are for your release builds),
  62. * the log messages above your logging threshold will automatically be compiled out.
  63. *
  64. * (If the compiler sees LOG_LEVEL_DEF/ddLogLevel declared as a constant, the compiler simply checks to see
  65. * if the 'if' statement would execute, and if not it strips it from the binary.)
  66. *
  67. * We also define shorthand versions for asynchronous and synchronous logging.
  68. **/
  69. #define AWSDD_LOG_MAYBE(async, lvl, flg, ctx, tag, fnct, frmt, ...) \
  70. do { AWSDD_LOG_MACRO(async, lvl, flg, ctx, tag, fnct, frmt, ##__VA_ARGS__); } while(0)
  71. #define LOG_MAYBE_TO_AWSDDLOG(ddlog, async, lvl, flg, ctx, tag, fnct, frmt, ...) \
  72. do { LOG_MACRO_TO_AWSDDLOG(ddlog, async, lvl, flg, ctx, tag, fnct, frmt, ##__VA_ARGS__); } while(0)
  73. /**
  74. * Ready to use log macros with no context or tag.
  75. **/
  76. #define AWSDDLogError(frmt, ...) AWSDD_LOG_MAYBE(NO, [AWSDDLog sharedInstance].logLevel, AWSDDLogFlagError, 0, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
  77. #define AWSDDLogWarn(frmt, ...) AWSDD_LOG_MAYBE(AWSDD_LOG_ASYNC_ENABLED, [AWSDDLog sharedInstance].logLevel, AWSDDLogFlagWarning, 0, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
  78. #define AWSDDLogInfo(frmt, ...) AWSDD_LOG_MAYBE(AWSDD_LOG_ASYNC_ENABLED, [AWSDDLog sharedInstance].logLevel, AWSDDLogFlagInfo, 0, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
  79. #define AWSDDLogDebug(frmt, ...) AWSDD_LOG_MAYBE(AWSDD_LOG_ASYNC_ENABLED, [AWSDDLog sharedInstance].logLevel, AWSDDLogFlagDebug, 0, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
  80. #define AWSDDLogVerbose(frmt, ...) AWSDD_LOG_MAYBE(AWSDD_LOG_ASYNC_ENABLED, [AWSDDLog sharedInstance].logLevel, AWSDDLogFlagVerbose, 0, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
  81. #define AWSDDLogErrorToAWSDDLog(ddlog, frmt, ...) LOG_MAYBE_TO_AWSDDLOG(ddlog, NO, [AWSDDLog sharedInstance].logLevel, AWSDDLogFlagError, 0, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
  82. #define AWSDDLogWarnToAWSDDLog(ddlog, frmt, ...) LOG_MAYBE_TO_AWSDDLOG(ddlog, AWSDD_LOG_ASYNC_ENABLED, [AWSDDLog sharedInstance].logLevel, AWSDDLogFlagWarning, 0, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
  83. #define AWSDDLogInfoToAWSDDLog(ddlog, frmt, ...) LOG_MAYBE_TO_AWSDDLOG(ddlog, AWSDD_LOG_ASYNC_ENABLED, [AWSDDLog sharedInstance].logLevel, AWSDDLogFlagInfo, 0, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
  84. #define AWSDDLogDebugToAWSDDLog(ddlog, frmt, ...) LOG_MAYBE_TO_AWSDDLOG(ddlog, AWSDD_LOG_ASYNC_ENABLED, [AWSDDLog sharedInstance].logLevel, AWSDDLogFlagDebug, 0, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
  85. #define AWSDDLogVerboseToAWSDDLog(ddlog, frmt, ...) LOG_MAYBE_TO_AWSDDLOG(ddlog, AWSDD_LOG_ASYNC_ENABLED, [AWSDDLog sharedInstance].logLevel, AWSDDLogFlagVerbose, 0, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)