No Description

AWSDDLog+LOGV.h 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 LOG_ASYNC_ENABLED
  24. #define LOG_ASYNC_ENABLED YES
  25. #endif
  26. /**
  27. * This is the single macro that all other macros below compile into.
  28. * This big multiline macro makes all the other macros easier to read.
  29. **/
  30. #define LOGV_MACRO(isAsynchronous, lvl, flg, ctx, atag, fnct, frmt, avalist) \
  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 \
  40. args : avalist]
  41. /**
  42. * Define version of the macro that only execute if the log level is above the threshold.
  43. * The compiled versions essentially look like this:
  44. *
  45. * if (logFlagForThisLogMsg & ddLogLevel) { execute log message }
  46. *
  47. * When LOG_LEVEL_DEF is defined as ddLogLevel.
  48. *
  49. * As shown further below, Lumberjack actually uses a bitmask as opposed to primitive log levels.
  50. * This allows for a great amount of flexibility and some pretty advanced fine grained logging techniques.
  51. *
  52. * Note that when compiler optimizations are enabled (as they are for your release builds),
  53. * the log messages above your logging threshold will automatically be compiled out.
  54. *
  55. * (If the compiler sees LOG_LEVEL_DEF/ddLogLevel declared as a constant, the compiler simply checks to see
  56. * if the 'if' statement would execute, and if not it strips it from the binary.)
  57. *
  58. * We also define shorthand versions for asynchronous and synchronous logging.
  59. **/
  60. #define LOGV_MAYBE(async, lvl, flg, ctx, tag, fnct, frmt, avalist) \
  61. do { if(lvl & flg) LOGV_MACRO(async, lvl, flg, ctx, tag, fnct, frmt, avalist); } while(0)
  62. /**
  63. * Ready to use log macros with no context or tag.
  64. **/
  65. #define AWSDDLogVError(frmt, avalist) LOGV_MAYBE(NO, LOG_LEVEL_DEF, AWSDDLogFlagError, 0, nil, __PRETTY_FUNCTION__, frmt, avalist)
  66. #define AWSDDLogVWarn(frmt, avalist) LOGV_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, AWSDDLogFlagWarning, 0, nil, __PRETTY_FUNCTION__, frmt, avalist)
  67. #define AWSDDLogVInfo(frmt, avalist) LOGV_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, AWSDDLogFlagInfo, 0, nil, __PRETTY_FUNCTION__, frmt, avalist)
  68. #define AWSDDLogVDebug(frmt, avalist) LOGV_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, AWSDDLogFlagDebug, 0, nil, __PRETTY_FUNCTION__, frmt, avalist)
  69. #define AWSDDLogVVerbose(frmt, avalist) LOGV_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, AWSDDLogFlagVerbose, 0, nil, __PRETTY_FUNCTION__, frmt, avalist)