| 1 | // This is a simple test that sends logging records to the Client |
| 2 | // Logging Daemon running on the localhost. This daemon then forwards |
| 3 | // them to the Server Logging Daemon. If there is no Server Logging |
| 4 | // Daemon, the logging records will be written to stderr. |
| 5 | |
| 6 | #include "ace/OS_NS_time.h" |
| 7 | #include "ace/OS_NS_stdlib.h" |
| 8 | #include "ace/Log_Msg.h" |
| 9 | #include "ace/Log_Record.h" |
| 10 | |
| 11 | int |
| 12 | ACE_TMAIN (int argc, ACE_TCHAR *argv[]) |
| 13 | { |
| 14 | const ACE_TCHAR *prog_name = argv[0]; |
| 15 | int iterations = argc < 2 ? 10 : ACE_OS::atoi (argv[1]); |
| 16 | const ACE_TCHAR *logger_key = argc < 3 ? ACE_DEFAULT_LOGGER_KEY : argv[2]; |
| 17 | int verbose = argc < 4 ? 0 : ACE_Log_Msg::VERBOSE; |
| 18 | |
| 19 | ACE_OS::srand ((u_int) ACE_OS::time (0)); |
| 20 | |
| 21 | if (ACE_LOG_MSG->open (prog_name, ACE_Log_Msg::LOGGER, logger_key) == -1) |
| 22 | { |
| 23 | ACE_ERROR ((LM_ERROR, "Cannot open logger, using STDERR\n")); |
| 24 | |
| 25 | if (ACE_LOG_MSG->open (prog_name, ACE_Log_Msg::STDERR | verbose) == -1) |
| 26 | ACE_ERROR_RETURN ((LM_ERROR, "Cannot open logger\n"), -1); |
| 27 | } |
| 28 | |
| 29 | ACE_DEBUG ((LM_STARTUP, "starting up the test\n")); |
| 30 | |
| 31 | for (int i = 0; i < iterations; i++) |
| 32 | { |
| 33 | size_t priority = ACE_OS::rand () % int (LM_MAX); |
| 34 | ACE_POW (priority); |
| 35 | ACE_Log_Priority log_priority = ACE_Log_Priority (priority); |
| 36 | ACE_DEBUG ((log_priority, |
| 37 | "random message %s (%d)...\n", |
| 38 | ACE_Log_Record::priority_name (log_priority), |
| 39 | priority)); |
| 40 | } |
| 41 | |
| 42 | ACE_DEBUG ((LM_SHUTDOWN, "closing down the test\n")); |
| 43 | |
| 44 | #if defined (ACE_WIN32) |
| 45 | // !!Important, Winsock is broken in that if you don't close |
| 46 | // down the connection before exiting main, you'll lose data. |
| 47 | // More over, your server might get "Access Violation" from |
| 48 | // within Winsock functions. |
| 49 | |
| 50 | // Here we close down the connection to Logger by redirecting |
| 51 | // the logging destination back to stderr. |
| 52 | ACE_LOG_MSG->open (0, ACE_Log_Msg::STDERR, 0); |
| 53 | #endif /* ACE_WIN32 */ |
| 54 | |
| 55 | return 0; |
| 56 | } |