Branch: Tag:

2002-03-19

2002-03-19 13:27:42 by Martin Stjernholm <mast@lysator.liu.se>

Added some comments to document the TRACE_* macros. Added
SIMPLE_TRACE_* variants which are more convenient than the traditional
ones.

Rev: server/etc/include/request_trace.h:1.10

2:   //   // Some stuff to do logging of a request through the server.   // - // $Id: request_trace.h,v 1.9 2002/03/12 13:38:38 mast Exp $ + // $Id: request_trace.h,v 1.10 2002/03/19 13:27:42 mast Exp $      #ifndef REQUEST_TRACE_H   #define REQUEST_TRACE_H
10:   #include <roxen.h>   #include <module.h>    + // Note that TRACE_ENTER and TRACE_LEAVE take html encoded message + // strings. Messages are preferably a single line, and they should not + // end with period and/or newline. +    #ifdef REQUEST_TRACE      # define TRACE_ENTER(A,B) Roxen->trace_enter (id, (A), (B))
37:      #endif    + // SIMPLE_TRACE_ENTER and SIMPLE_TRACE_LEAVE are simpler variants of + // the above macros: They handle sprintf style format lists and don't + // take html encoded messages. Note the reversed argument order in + // SIMPLE_TRACE_ENTER compared to TRACE_ENTER. +  + #define SIMPLE_TRACE_ENTER(OBJ, MSG...) do { \ +  array _msg_arr_; \ +  TRACE_ENTER (Roxen.html_encode_string ( \ +  (_msg_arr_ = ({MSG}), \ +  sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \ +  (sizeof (_msg_arr_) ? _msg_arr_[0] : ""))), \ +  (OBJ)); \ +  } while (0) +  + #define SIMPLE_TRACE_LEAVE(MSG...) do { \ +  array _msg_arr_; \ +  TRACE_LEAVE (Roxen.html_encode_string ( \ +  (_msg_arr_ = ({MSG}), \ +  sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \ +  (sizeof (_msg_arr_) ? _msg_arr_[0] : "")))); \ +  } while (0) +    // The following variant should be used inside RXML.Frame callbacks   // such as do_enter. In addition to the request trace, it does rxml   // debug logging which is activated with the DEBUG define in   // combination with the magic _debug_ tag argument or the RXML_VERBOSE   // or RXML_REQUEST_VERBOSE defines.   // - // Note that these two macros do not take html encoded messages, as - // opposed to TRACE_ENTER and TRACE_LEAVE. + // These two macros do not take html encoded messages, as opposed to + // TRACE_ENTER and TRACE_LEAVE.      #define TAG_TRACE_ENTER(MSG...) do { \    array _msg_arr_; \
52:    TRACE_ENTER ("tag &lt;" + (tag && tag->name) + "&gt; " + \    Roxen.html_encode_string ( \    (_msg_arr_ = ({MSG}), \ -  _msg_ = sizeof (_msg_arr_) > 1 ? \ -  sprintf (@_msg_arr_) : _msg_arr_[0])), \ +  _msg_ = sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \ +  (sizeof (_msg_arr_) ? _msg_arr_[0] : ""))), \    tag); \    DO_IF_DEBUG ( \    if (TAG_DEBUG_TEST (flags & RXML.FLAG_DEBUG)) \    tag_debug ("%O: %s\n", this_object(), \ -  _msg_ || (_msg_arr_ = ({MSG}), \ -  sizeof (_msg_arr_) > 1 ? \ -  sprintf (@_msg_arr_) : _msg_arr_[0])); \ +  _msg_ || \ +  (_msg_arr_ = ({MSG}), \ +  sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \ +  (sizeof (_msg_arr_) ? _msg_arr_[0] : ""))); \    ); \    } while (0)   
69:    string _msg_; \    TRACE_LEAVE (Roxen.html_encode_string ( \    (_msg_arr_ = ({MSG}), \ -  _msg_ = sizeof (_msg_arr_) > 1 ? \ -  sprintf (@_msg_arr_) : _msg_arr_[0]))); \ +  _msg_ = sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \ +  (sizeof (_msg_arr_) ? _msg_arr_[0] : "")))); \    DO_IF_DEBUG ( \    if (TAG_DEBUG_TEST (flags & RXML.FLAG_DEBUG)) { \    if (!_msg_) { \    _msg_arr_ = ({MSG}); \ -  _msg_ = sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : _msg_arr_[0]; \ +  _msg_ = \ +  sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \ +  (sizeof (_msg_arr_) ? _msg_arr_[0] : ""); \    } \    if (sizeof (_msg_)) tag_debug ("%O: %s\n", this_object(), _msg_); \    } \