You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DDLog+LOGV.h 3.8 KiB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Software License Agreement (BSD License)
  2. //
  3. // Copyright (c) 2010-2015, 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 DD_LEGACY_MACROS
  17. #define DD_LEGACY_MACROS 0
  18. #endif
  19. #import "DDLog.h"
  20. /**
  21. * The constant/variable/method responsible for controlling the current log level.
  22. **/
  23. #ifndef LOG_LEVEL_DEF
  24. #define LOG_LEVEL_DEF ddLogLevel
  25. #endif
  26. /**
  27. * Whether async should be used by log messages, excluding error messages that are always sent sync.
  28. **/
  29. #ifndef LOG_ASYNC_ENABLED
  30. #define LOG_ASYNC_ENABLED YES
  31. #endif
  32. /**
  33. * This is the single macro that all other macros below compile into.
  34. * This big multiline macro makes all the other macros easier to read.
  35. **/
  36. #define LOGV_MACRO(isAsynchronous, lvl, flg, ctx, atag, fnct, frmt, avalist) \
  37. [DDLog log : isAsynchronous \
  38. level : lvl \
  39. flag : flg \
  40. context : ctx \
  41. file : __FILE__ \
  42. function : fnct \
  43. line : __LINE__ \
  44. tag : atag \
  45. format : frmt \
  46. args : avalist]
  47. /**
  48. * Define version of the macro that only execute if the log level is above the threshold.
  49. * The compiled versions essentially look like this:
  50. *
  51. * if (logFlagForThisLogMsg & ddLogLevel) { execute log message }
  52. *
  53. * When LOG_LEVEL_DEF is defined as ddLogLevel.
  54. *
  55. * As shown further below, Lumberjack actually uses a bitmask as opposed to primitive log levels.
  56. * This allows for a great amount of flexibility and some pretty advanced fine grained logging techniques.
  57. *
  58. * Note that when compiler optimizations are enabled (as they are for your release builds),
  59. * the log messages above your logging threshold will automatically be compiled out.
  60. *
  61. * (If the compiler sees LOG_LEVEL_DEF/ddLogLevel declared as a constant, the compiler simply checks to see
  62. * if the 'if' statement would execute, and if not it strips it from the binary.)
  63. *
  64. * We also define shorthand versions for asynchronous and synchronous logging.
  65. **/
  66. #define LOGV_MAYBE(async, lvl, flg, ctx, tag, fnct, frmt, avalist) \
  67. do { if(lvl & flg) LOGV_MACRO(async, lvl, flg, ctx, tag, fnct, frmt, avalist); } while(0)
  68. /**
  69. * Ready to use log macros with no context or tag.
  70. **/
  71. #define DDLogVError(frmt, avalist) LOGV_MAYBE(NO, LOG_LEVEL_DEF, DDLogFlagError, 0, nil, __PRETTY_FUNCTION__, frmt, avalist)
  72. #define DDLogVWarn(frmt, avalist) LOGV_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, DDLogFlagWarning, 0, nil, __PRETTY_FUNCTION__, frmt, avalist)
  73. #define DDLogVInfo(frmt, avalist) LOGV_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, DDLogFlagInfo, 0, nil, __PRETTY_FUNCTION__, frmt, avalist)
  74. #define DDLogVDebug(frmt, avalist) LOGV_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, DDLogFlagDebug, 0, nil, __PRETTY_FUNCTION__, frmt, avalist)
  75. #define DDLogVVerbose(frmt, avalist) LOGV_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, DDLogFlagVerbose, 0, nil, __PRETTY_FUNCTION__, frmt, avalist)