Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / APG / Logging / Trace.h
blob58c8827bd70260d2839a119eb5868006834468ce
1 #ifndef TRACE_H
2 #define TRACE_H
4 #include "ace/Log_Msg.h"
6 // Listing 1 code/ch03
7 class Trace
9 public:
10 Trace (const ACE_TCHAR *prefix,
11 const ACE_TCHAR *name,
12 int line,
13 const ACE_TCHAR *file)
15 this->prefix_ = prefix;
16 this->name_ = name;
17 this->line_ = line;
18 this->file_ = file;
20 ACE_Log_Msg *lm = ACE_LOG_MSG;
21 if (lm->tracing_enabled ()
22 && lm->trace_active () == 0)
24 lm->trace_active (1);
25 ACE_DEBUG
26 ((LM_TRACE,
27 ACE_TEXT ("%s%*s(%t) calling %s in file `%s'")
28 ACE_TEXT (" on line %d\n"),
29 this->prefix_,
30 Trace::nesting_indent_ * lm->inc (),
31 ACE_TEXT (""),
32 this->name_,
33 this->file_,
34 this->line_));
35 lm->trace_active (0);
39 void setLine (int line)
41 this->line_ = line;
44 ~Trace ()
46 ACE_Log_Msg *lm = ACE_LOG_MSG;
47 if (lm->tracing_enabled ()
48 && lm->trace_active () == 0)
50 lm->trace_active (1);
51 ACE_DEBUG
52 ((LM_TRACE,
53 ACE_TEXT ("%s%*s(%t) leaving %s in file `%s'")
54 ACE_TEXT (" on line %d\n"),
55 this->prefix_,
56 Trace::nesting_indent_ * lm->dec (),
57 ACE_TEXT (""),
58 this->name_,
59 this->file_,
60 this->line_));
61 lm->trace_active (0);
65 private:
66 enum { nesting_indent_ = 3 };
68 const ACE_TCHAR *prefix_;
69 const ACE_TCHAR *name_;
70 const ACE_TCHAR *file_;
71 int line_;
73 // Listing 1
75 // Listing 2 code/ch03
76 #define TRACE_PREFIX ACE_TEXT ("TRACE ")
78 #if defined (TRACE)
79 #undef TRACE
80 #endif /* TRACE */
82 #if (ACE_NTRACE == 1)
83 # define TRACE(X)
84 # define TRACE_RETURN(V) return V;
85 # define TRACE_RETURN_VOID()
86 #else
87 # define TRACE(X) \
88 Trace ____ (TRACE_PREFIX, \
89 ACE_TEXT (X), \
90 __LINE__, \
91 ACE_TEXT (__FILE__))
93 # define TRACE_RETURN(V) \
94 do { ____.setLine(__LINE__); return V; } while (0)
96 # define TRACE_RETURN_VOID() \
97 do { ____.setLine(__LINE__); } while (0)
98 #endif
99 // Listing 2
101 //////////////////////////////////////////////////
103 // Listing 3 code/ch03
105 #define DEBUG_PREFIX ACE_TEXT ("DEBUG%I")
106 #define INFO_PREFIX ACE_TEXT ("INFO%I")
107 #define NOTICE_PREFIX ACE_TEXT ("NOTICE%I")
108 #define WARNING_PREFIX ACE_TEXT ("WARNING%I")
109 #define ERROR_PREFIX ACE_TEXT ("ERROR%I")
110 #define CRITICAL_PREFIX ACE_TEXT ("CRITICAL%I")
111 #define ALERT_PREFIX ACE_TEXT ("ALERT%I")
112 #define EMERGENCY_PREFIX ACE_TEXT ("EMERGENCY%I")
114 #define MY_DEBUG(X) \
115 ACE_DEBUG(( LM_DEBUG, \
116 DEBUG_PREFIX \
118 #define MY_INFO(X) \
119 ACE_DEBUG(( LM_INFO, \
120 INFO_PREFIX \
122 #define MY_NOTICE(X) \
123 ACE_DEBUG(( LM_NOTICE, \
124 NOTICE_PREFIX \
126 #define MY_WARNING(X) \
127 ACE_DEBUG(( LM_WARNING, \
128 WARNING_PREFIX \
130 #define MY_ERROR(X) \
131 ACE_DEBUG(( LM_ERROR, \
132 ERROR_PREFIX \
134 #define MY_CRITICAL(X) \
135 ACE_DEBUG(( LM_CRITICAL, \
136 CRITICAL_PREFIX \
138 #define MY_ALERT(X) \
139 ACE_DEBUG(( LM_ALERT, \
140 ALERT_PREFIX \
142 #define MY_EMERGENCY(X) \
143 ACE_DEBUG(( LM_EMERGENCY, \
144 EMERGENCY_PREFIX \
146 // Listing 3
148 #endif /* TRACE_H */