HTTPLogging.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * In order to provide fast and flexible logging, this project uses Cocoa Lumberjack.
  3. *
  4. * The Google Code page has a wealth of documentation if you have any questions.
  5. * https://github.com/robbiehanson/CocoaLumberjack
  6. *
  7. * Here's what you need to know concerning how logging is setup for CocoaHTTPServer:
  8. *
  9. * There are 4 log levels:
  10. * - Error
  11. * - Warning
  12. * - Info
  13. * - Verbose
  14. *
  15. * In addition to this, there is a Trace flag that can be enabled.
  16. * When tracing is enabled, it spits out the methods that are being called.
  17. *
  18. * Please note that tracing is separate from the log levels.
  19. * For example, one could set the log level to warning, and enable tracing.
  20. *
  21. * All logging is asynchronous, except errors.
  22. * To use logging within your own custom files, follow the steps below.
  23. *
  24. * Step 1:
  25. * Import this header in your implementation file:
  26. *
  27. * #import "HTTPLogging.h"
  28. *
  29. * Step 2:
  30. * Define your logging level in your implementation file:
  31. *
  32. * // Log levels: off, error, warn, info, verbose
  33. * static const int httpLogLevel = HTTP_LOG_LEVEL_VERBOSE;
  34. *
  35. * If you wish to enable tracing, you could do something like this:
  36. *
  37. * // Debug levels: off, error, warn, info, verbose
  38. * static const int httpLogLevel = HTTP_LOG_LEVEL_INFO | HTTP_LOG_FLAG_TRACE;
  39. *
  40. * Step 3:
  41. * Replace your NSLog statements with HTTPLog statements according to the severity of the message.
  42. *
  43. * NSLog(@"Fatal error, no dohickey found!"); -> HTTPLogError(@"Fatal error, no dohickey found!");
  44. *
  45. * HTTPLog works exactly the same as NSLog.
  46. * This means you can pass it multiple variables just like NSLog.
  47. **/
  48. // Define logging context for every log message coming from the HTTP server.
  49. // The logging context can be extracted from the DDLogMessage from within the logging framework,
  50. // which gives loggers, formatters, and filters the ability to optionally process them differently.
  51. #define HTTP_LOG_CONTEXT 80
  52. // Configure log levels.
  53. #define HTTP_LOG_FLAG_ERROR (1 << 0) // 0...00001
  54. #define HTTP_LOG_FLAG_WARN (1 << 1) // 0...00010
  55. #define HTTP_LOG_FLAG_INFO (1 << 2) // 0...00100
  56. #define HTTP_LOG_FLAG_VERBOSE (1 << 3) // 0...01000
  57. #define HTTP_LOG_LEVEL_OFF 0 // 0...00000
  58. #define HTTP_LOG_LEVEL_ERROR (HTTP_LOG_LEVEL_OFF | HTTP_LOG_FLAG_ERROR) // 0...00001
  59. #define HTTP_LOG_LEVEL_WARN (HTTP_LOG_LEVEL_ERROR | HTTP_LOG_FLAG_WARN) // 0...00011
  60. #define HTTP_LOG_LEVEL_INFO (HTTP_LOG_LEVEL_WARN | HTTP_LOG_FLAG_INFO) // 0...00111
  61. #define HTTP_LOG_LEVEL_VERBOSE (HTTP_LOG_LEVEL_INFO | HTTP_LOG_FLAG_VERBOSE) // 0...01111
  62. // Setup fine grained logging.
  63. // The first 4 bits are being used by the standard log levels (0 - 3)
  64. //
  65. // We're going to add tracing, but NOT as a log level.
  66. // Tracing can be turned on and off independently of log level.
  67. #define HTTP_LOG_FLAG_TRACE (1 << 4) // 0...10000
  68. // Setup the usual boolean macros.
  69. #define HTTP_LOG_ERROR (httpLogLevel & HTTP_LOG_FLAG_ERROR)
  70. #define HTTP_LOG_WARN (httpLogLevel & HTTP_LOG_FLAG_WARN)
  71. #define HTTP_LOG_INFO (httpLogLevel & HTTP_LOG_FLAG_INFO)
  72. #define HTTP_LOG_VERBOSE (httpLogLevel & HTTP_LOG_FLAG_VERBOSE)
  73. #define HTTP_LOG_TRACE (httpLogLevel & HTTP_LOG_FLAG_TRACE)
  74. // Configure asynchronous logging.
  75. // We follow the default configuration,
  76. // but we reserve a special macro to easily disable asynchronous logging for debugging purposes.
  77. #define HTTP_LOG_ASYNC_ENABLED YES
  78. #define HTTP_LOG_ASYNC_ERROR ( NO && HTTP_LOG_ASYNC_ENABLED)
  79. #define HTTP_LOG_ASYNC_WARN (YES && HTTP_LOG_ASYNC_ENABLED)
  80. #define HTTP_LOG_ASYNC_INFO (YES && HTTP_LOG_ASYNC_ENABLED)
  81. #define HTTP_LOG_ASYNC_VERBOSE (YES && HTTP_LOG_ASYNC_ENABLED)
  82. #define HTTP_LOG_ASYNC_TRACE (YES && HTTP_LOG_ASYNC_ENABLED)
  83. // Define logging primitives.
  84. #define HTTPLogError(...) { }
  85. #define HTTPLogWarn(...) { }
  86. #define HTTPLogInfo(...) { }
  87. #define HTTPLogVerbose(...) { }
  88. #define HTTPLogTrace() { }
  89. #define HTTPLogTrace2(...) { }
  90. #define HTTPLogCError(...) { }
  91. #define HTTPLogCWarn(...) { }
  92. #define HTTPLogCInfo(...) { }
  93. #define HTTPLogCVerbose(...) { }
  94. #define HTTPLogCTrace() { }
  95. #define HTTPLogCTrace2(...) { }