Buffered diagnostic output and optional HTTP protocol tracing.
Install a flush callback at startup to enable output. If the library is built without HTTP_TRACE, output functions have no effect. This header enables HTTP_TRACE by default unless NO_HTTP_TRACE is defined.
Priority zero is highest. A message is emitted when its priority is less than or equal to the configured filter (initially 5). Optional HTTP trace categories are initially disabled and use priority 5 when enabled.
Output is flushed when the buffer fills, after a write that leaves a newline in the buffer, or by an explicit flush(). Partial lines may remain buffered. The default payload buffer is approximately 80 bytes.
Configure the callback and buffer size at startup, before concurrent use. Do not change or close the trace while a writer is locked. Output functions serialize access with the trace mutex; the callback executes under that mutex and must not call back into trace output.
- See also
- HttpTrace::setFLushCallback
|
| static void | setFLushCallback (HttpTrace_Flush fcb) |
| | The HTTP_TRACE compile time macro adds the trace library to the Barracuda library, but the trace functions will have no effect if you do not provide a callback function. More...
|
| |
| static void | vprintf (int prio, const char *fmt, va_list argList) |
| | Write data to the trace buffer. More...
|
| |
| static void | printf (int prio, const char *fmt,...) |
| | Write data to the trace buffer. More...
|
| |
| static void | write (int prio, const char *buf, int len=-1) |
| | Write data to the trace buffer. More...
|
| |
| static int | setPrio (int prio) |
| | Set the trace message priority filter. More...
|
| |
| static BufPrint * | getWriter () |
| | Get and lock the trace BufPrint object. More...
|
| |
| static void | releaseWriter (void) |
| | Release a writer lock obtained by a successful getWriter call. More...
|
| |
| static void | setRequest (bool cmd) |
| | Enable or disable request-line tracing. More...
|
| |
| static void | setRequestHeaders (bool cmd) |
| | If enabled, the web-server dumps the content of the request header to the trace buffer. More...
|
| |
| static void | setResponseHeaders (bool cmd) |
| | If enabled, the web-server dumps the content of the response header to the trace buffer. More...
|
| |
| static void | setResponseBody (bool cmd) |
| | If enabled, the web-server dumps the content of the response body to the trace buffer. More...
|
| |
| static void | setHttp11State (bool cmd) |
| | If enabled, prints the status for each active client connection of the internal "HTTP 1.1 persistent connection" state machine to the trace buffer. More...
|
| |
| static void | setReqBufOverflow (bool cmd) |
| | Report when an HTTP request exceeds the configured request buffer. More...
|
| |
| static int | setBufSize (int size) |
| | Set trace buffer size. More...
|
| |
| static void | flush () |
| | Force a flush on data in trace buffer; i.e., call the flush callback. More...
|
| |
| static bool | isRequestSet () |
| | Returns true if request-line tracing is enabled. More...
|
| |
| static bool | isRequestHeadersSet () |
| | Returns true if request-header tracing is enabled. More...
|
| |
| static bool | isResponseHeadersSet () |
| | Returns true if response-header tracing is enabled. More...
|
| |
| static bool | isResponseBodySet () |
| | Returns true if response-body tracing is enabled. More...
|
| |
| static bool | isHttp11StateSet () |
| | Returns true if HTTP/1.1 connection-state tracing is enabled. More...
|
| |
The HTTP_TRACE compile time macro adds the trace library to the Barracuda library, but the trace functions will have no effect if you do not provide a callback function.
This function is not re-entrant; therefore, you should call this function at system startup.
The following example dumps data to the console:
void flush2Console(char* buf, int bufLen)
{
buf[bufLen] = 0;
}
.
.
BA_API void HttpTrace_setFLushCallback(HttpTrace_Flush fcb)
The HTTP_TRACE compile time macro adds the trace library to the Barracuda library,...
static void printf(int prio, const char *fmt,...)
Write data to the trace buffer.
Definition: HttpTrace.h:377
Newline-terminated output is flushed automatically. To deliver partial lines promptly, flush explicitly, for example after a dispatcher poll.
for(;;)
{
myDispatcher->run(1000);
}
static void flush()
Force a flush on data in trace buffer; i.e., call the flush callback.
Definition: HttpTrace.h:404
- Parameters
-
| [in] | fcb | Callback retained until replaced, or NULL to disable output. Allocation failure during initialization leaves tracing disabled; HttpTrace_getFLushCallback returns NULL in that case. |
| void HttpTrace::setHttp11State |
( |
bool |
cmd | ) |
|
|
static |
If enabled, prints the status for each active client connection of the internal "HTTP 1.1 persistent connection" state machine to the trace buffer.
The state machine can be in one of 5 states. As an example, a non-persistent connection will go through the following states for each request:
Connection 56c1f0 3944 trans: Free -> Connected
Connection 56c1f0 3944 trans: Connected -> Running
Connection 56c1f0 3944 trans: Running -> Terminated
Connection 56c1f0 -001 trans: Terminated -> Free
A persistent HTTP connection is in one of the Connected or Running states.
Connection 56c290 3944 trans: Connected -> Running
Connection 56c290 3944 trans: Running -> Connected
Connection 56c290 3944 trans: Connected -> Running
Connection 56c290 3944 trans: Running -> Connected
Connection 56c290 3944 trans: Connected -> Running
Connection 56c290 3944 trans: Running -> Connected
- Parameters
-
| [in] | cmd | TRUE enables this trace category; FALSE disables it. |