2 //=============================================================================
4 * @file test_log_msg.cpp
6 * This program tests the ACE_Log_Msg abstraction and demontrates
7 * several common use cases.
9 * @author Douglas Schmidt <d.schmidt@vanderbilt.edu>
11 //=============================================================================
14 #include "ace/OS_main.h"
16 // FUZZ: disable check_for_streams_include
17 #include "ace/streams.h"
19 #include "ace/Log_Msg.h"
20 #include "ace/OS_NS_unistd.h"
21 #include "ace/OS_NS_stdlib.h"
40 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
44 if (argc
> 1) // Just give a dummy command-line argument to trigger this path.
46 if (ACE_LOG_MSG
->open (argv
[0],
47 ACE_Log_Msg::OSTREAM
) == -1)
49 "cannot open logger!!!\n"));
52 // Check to see what happened.
53 if (ACE_LOG_MSG
->op_status () == -1
54 && ACE_LOG_MSG
->errnum () == EWOULDBLOCK
)
56 "op_status and errnum work!\n"));
59 "op_status and errnum failed!\n"));
61 else // The default behavior is to log to STDERR...
63 if (ACE_LOG_MSG
->open (argv
[0]) == -1)
65 "cannot open logger!!!\n"));
69 // Check to see what happened.
70 if (ACE_LOG_MSG
->op_status () == -1
71 && ACE_LOG_MSG
->errnum () == EWOULDBLOCK
)
73 "op_status and errnum work!\n"));
76 "op_status and errnum failed!\n"));
78 // Exercise many different combinations of STDERR and OSTREAM.
80 double f
= 3.1416 * counter
++;
91 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
93 ACE_LOG_MSG
->set_flags (ACE_Log_Msg::OSTREAM
);
94 ACE_LOG_MSG
->msg_ostream (&cout
);
97 i
= 10000 * counter
++;
99 // This message will print twice - once for OSTREAM and once for
103 "%10f, %*s%s = %d\n",
110 ACE_LOG_MSG
->clr_flags (ACE_Log_Msg::STDERR
);
112 f
= 3.1416 * counter
;
113 i
= 10000 * counter
++;
116 "%10f, %*s%s = %d\n",
123 ACE_LOG_MSG
->msg_ostream (0);
125 ACE_LOG_MSG
->set_flags (ACE_Log_Msg::STDERR
);
127 f
= 3.1416 * counter
;
128 i
= 10000 * counter
++;
131 "%10f, %*s%s = %d\n",
138 ACE_LOG_MSG
->clr_flags (ACE_Log_Msg::OSTREAM
);
139 ACE_LOG_MSG
->msg_ostream (&cerr
);
141 f
= 3.1416 * counter
;
142 i
= 10000 * counter
++;
145 "%10f, %*s%s = %d\n",
152 #endif /* !defined (ACE_LACKS_IOSTREAM_TOTALLY) */
154 static int array
[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};
156 // Print out the binary bytes of the array in hex form.
157 ACE_LOG_MSG
->log_hexdump (LM_DEBUG
,
161 // Disable the LM_DEBUG and LM_INFO messages at the process level.
162 u_long priority_mask
=
163 ACE_LOG_MSG
->priority_mask (ACE_Log_Msg::PROCESS
);
164 ACE_CLR_BITS (priority_mask
,
166 ACE_LOG_MSG
->priority_mask (priority_mask
,
167 ACE_Log_Msg::PROCESS
);
170 "This LM_INFO message should not print!\n"));
171 ACE_DEBUG ((LM_DEBUG
,
172 "This LM_DEBUG message should not print!\n"));
174 ACE_SET_BITS (priority_mask
,
176 ACE_LOG_MSG
->priority_mask (priority_mask
,
177 ACE_Log_Msg::PROCESS
);
180 "This LM_INFO message should print!\n"));
181 ACE_DEBUG ((LM_DEBUG
,
182 "This LM_DEBUG message should not print!\n"));
184 ACE_CLR_BITS (priority_mask
, LM_INFO
);
185 ACE_LOG_MSG
->priority_mask (priority_mask
,
186 ACE_Log_Msg::PROCESS
);
189 "This LM_INFO message should not print!\n"));
190 ACE_DEBUG ((LM_DEBUG
,
191 "This LM_DEBUG message should not print!\n"));
193 char badname
[] = "badname";
199 if (ACE_OS::execv (badname
,
202 ACE_ERROR ((LM_ERROR
,