HTTPLogging.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/CocoaLumberjack/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 DDLogLevel httpLogLevel = DDLogLevelVerbose;
  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 DDLogLevel httpLogLevel = DDLogLevelInfo | 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. #import <CocoaLumberjack/CocoaLumberjack.h>
  49. // Define logging context for every log message coming from the HTTP server.
  50. // The logging context can be extracted from the DDLogMessage from within the logging framework,
  51. // which gives loggers, formatters, and filters the ability to optionally process them differently.
  52. #define HTTP_LOG_CONTEXT 80
  53. // Setup fine grained logging.
  54. // The first 4 bits are being used by the standard log levels (0 - 3)
  55. //
  56. // We're going to add tracing, but NOT as a log level.
  57. // Tracing can be turned on and off independently of log level.
  58. #define HTTP_LOG_FLAG_TRACE (1 << 4) // 0...10000
  59. // Configure asynchronous logging.
  60. // We follow the default configuration,
  61. // but we reserve a special macro to easily disable asynchronous logging for debugging purposes.
  62. #define HTTP_LOG_ASYNC_ENABLED YES
  63. // Define logging primitives.
  64. #define HTTPLogError(frmt, ...) LOG_MAYBE(NO, httpLogLevel, DDLogFlagError, HTTP_LOG_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
  65. #define HTTPLogWarn(frmt, ...) LOG_MAYBE(HTTP_LOG_ASYNC_ENABLED, httpLogLevel, DDLogFlagWarning, HTTP_LOG_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
  66. #define HTTPLogInfo(frmt, ...) LOG_MAYBE(HTTP_LOG_ASYNC_ENABLED, httpLogLevel, DDLogFlagInfo, HTTP_LOG_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
  67. #define HTTPLogVerbose(frmt, ...) LOG_MAYBE(HTTP_LOG_ASYNC_ENABLED, httpLogLevel, DDLogFlagVerbose, HTTP_LOG_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)
  68. #define HTTPLogTrace() LOG_MAYBE(HTTP_LOG_ASYNC_ENABLED, httpLogLevel, HTTP_LOG_FLAG_TRACE, HTTP_LOG_CONTEXT, nil, __PRETTY_FUNCTION__, @"%@[%p]: %@", THIS_FILE, self, THIS_METHOD)
  69. #define HTTPLogTrace2(frmt, ...) LOG_MAYBE(HTTP_LOG_ASYNC_ENABLED, httpLogLevel, HTTP_LOG_FLAG_TRACE, HTTP_LOG_CONTEXT, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__)