28a0802000-08-14Martin Stjernholm // -*- pike -*- // // Some stuff to do logging of a request through the server. //
76c8c12002-03-19Martin Stjernholm // $Id: request_trace.h,v 1.10 2002/03/19 13:27:42 mast Exp $
f2180f2002-03-12Martin Stjernholm  #ifndef REQUEST_TRACE_H #define REQUEST_TRACE_H #include <roxen.h> #include <module.h>
28a0802000-08-14Martin Stjernholm 
76c8c12002-03-19Martin Stjernholm // 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.
28a0802000-08-14Martin Stjernholm #ifdef REQUEST_TRACE # define TRACE_ENTER(A,B) Roxen->trace_enter (id, (A), (B)) # define TRACE_LEAVE(A) Roxen->trace_leave (id, (A)) #else
fa4f792000-03-13Martin Nilsson # define TRACE_ENTER(A,B) do{ \
4b09682001-11-01Henrik Grubbström (Grubba)  function(string,mixed ...:void) _trace_enter; \
3ef3d12001-11-01Henrik Grubbström (Grubba)  if(id && \ (_trace_enter = \ [function(string,mixed ...:void)]([mapping(string:mixed)]id->misc)-> \ trace_enter)) \ _trace_enter((A), (B)); \
fa4f792000-03-13Martin Nilsson  }while(0) # define TRACE_LEAVE(A) do{ \
4b09682001-11-01Henrik Grubbström (Grubba)  function(string:void) _trace_leave; \
3ef3d12001-11-01Henrik Grubbström (Grubba)  if(id && \ (_trace_leave = \ [function(string:void)]([mapping(string:mixed)]id->misc)-> \ trace_leave)) \ _trace_leave(A); \
fa4f792000-03-13Martin Nilsson  }while(0)
28a0802000-08-14Martin Stjernholm 
fa4f792000-03-13Martin Nilsson #endif
4717052001-05-07Per Hedbor 
76c8c12002-03-19Martin Stjernholm // 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)
f2180f2002-03-12Martin Stjernholm // 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.
50e0fa2002-03-12Martin Stjernholm //
76c8c12002-03-19Martin Stjernholm // These two macros do not take html encoded messages, as opposed to // TRACE_ENTER and TRACE_LEAVE.
f2180f2002-03-12Martin Stjernholm  #define TAG_TRACE_ENTER(MSG...) do { \ array _msg_arr_; \ string _msg_; \ TRACE_ENTER ("tag &lt;" + (tag && tag->name) + "&gt; " + \
50e0fa2002-03-12Martin Stjernholm  Roxen.html_encode_string ( \ (_msg_arr_ = ({MSG}), \
76c8c12002-03-19Martin Stjernholm  _msg_ = sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \ (sizeof (_msg_arr_) ? _msg_arr_[0] : ""))), \
f2180f2002-03-12Martin Stjernholm  tag); \ DO_IF_DEBUG ( \ if (TAG_DEBUG_TEST (flags & RXML.FLAG_DEBUG)) \ tag_debug ("%O: %s\n", this_object(), \
76c8c12002-03-19Martin Stjernholm  _msg_ || \ (_msg_arr_ = ({MSG}), \ sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \ (sizeof (_msg_arr_) ? _msg_arr_[0] : ""))); \
f2180f2002-03-12Martin Stjernholm  ); \ } while (0) #define TAG_TRACE_LEAVE(MSG...) do { \ array _msg_arr_; \ string _msg_; \
50e0fa2002-03-12Martin Stjernholm  TRACE_LEAVE (Roxen.html_encode_string ( \ (_msg_arr_ = ({MSG}), \
76c8c12002-03-19Martin Stjernholm  _msg_ = sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \ (sizeof (_msg_arr_) ? _msg_arr_[0] : "")))); \
f2180f2002-03-12Martin Stjernholm  DO_IF_DEBUG ( \ if (TAG_DEBUG_TEST (flags & RXML.FLAG_DEBUG)) { \ if (!_msg_) { \ _msg_arr_ = ({MSG}); \
76c8c12002-03-19Martin Stjernholm  _msg_ = \ sizeof (_msg_arr_) > 1 ? sprintf (@_msg_arr_) : \ (sizeof (_msg_arr_) ? _msg_arr_[0] : ""); \
f2180f2002-03-12Martin Stjernholm  } \ if (sizeof (_msg_)) tag_debug ("%O: %s\n", this_object(), _msg_); \ } \ ); \ } while (0)
4717052001-05-07Per Hedbor  #ifdef AVERAGE_PROFILING #define PROF_ENTER(X,Y) id->conf->avg_prof_enter( X, Y, id ) #define PROF_LEAVE(X,Y) id->conf->avg_prof_leave( X, Y, id ) #define COND_PROF_ENTER(X,Y,Z) if(X)PROF_ENTER(Y,Z) #define COND_PROF_LEAVE(X,Y,Z) if(X)PROF_LEAVE(Y,Z) #else #define PROF_ENTER(X,Y) #define PROF_LEAVE(X,Y) #define COND_PROF_ENTER(X,Y,Z) #define COND_PROF_LEAVE(X,Y,Z) #endif
f2180f2002-03-12Martin Stjernholm  #endif // !REQUEST_TRACE_H