26#include <core/exceptions/system.h>
27#include <core/threading/thread.h>
28#include <utils/logging/console.h>
29#include <utils/logging/file.h>
30#include <utils/logging/liblogger.h>
31#include <utils/system/argparser.h>
32#include <utils/system/signal.h>
44class LibLoggerQAThread :
public Thread
47 LibLoggerQAThread(
unsigned int thread_num,
unsigned int sleep_time_usec)
48 :
Thread(
"LibLoggerQAThread")
50 this->sleep_time_usec = sleep_time_usec;
51 this->thread_num = thread_num;
62 if ((thread_num % 4) == 0) {
63 LibLogger::log_debug(
"LibLoggerQA",
"%u: %u (debug)", thread_num, ++i);
64 }
else if ((thread_num % 3) == 0) {
65 LibLogger::log_info(
"LibLoggerQA",
"%u: %u (info)", thread_num, ++i);
66 }
else if ((thread_num % 2) == 0) {
67 LibLogger::log_warn(
"LibLoggerQA",
"%u: %u (warn)", thread_num, ++i);
69 LibLogger::log_error(
"LibLoggerQA",
"%u: %u (error)", thread_num, ++i);
71 usleep(sleep_time_usec);
75 unsigned int sleep_time_usec;
76 unsigned int thread_num;
85 unsigned int sleep_time_usec = 0;
86 unsigned int num_threads = 3;
88 if ((tmp = argp->
arg(
"s")) != NULL) {
89 sleep_time_usec = atoi(tmp);
91 if ((tmp = argp->
arg(
"n")) != NULL) {
92 num_threads = atoi(tmp);
93 if (num_threads < 0) {
99 for (
unsigned int i = 0; i < num_threads; ++i) {
100 threads.push_back(
new LibLoggerQAThread(i, sleep_time_usec));
106 for (tit = threads.begin(); tit != threads.end(); ++tit) {
113 handle_signal(
int signum)
115 printf(
"Signal received, cancelling threads\n");
116 for (tit = threads.begin(); tit != threads.end(); ++tit) {
119 printf(
"Threads cancelled\n");
125 for (tit = threads.begin(); tit != threads.end(); ++tit) {
128 for (tit = threads.begin(); tit != threads.end(); ++tit) {
134 list<Thread *> threads;
135 list<Thread *>::iterator tit;
140main(
int argc,
char **argv)
145 cout <<
"Usage: " << argv[0] <<
"[-s n] [-n n]" << endl
146 <<
" -s n Sleep time for thres in usec" << endl
147 <<
" -h this help message" << endl
148 <<
" -n n number of threads" << endl;
152 LibLoggerQAMain m(argp);
153 SignalManager::register_handler(SIGINT, &m);
154 SignalManager::ignore(SIGPIPE);
157 LibLogger::add_logger(
new FileLogger(
"qa_utils_liblogger.log"));
162 LibLogger::finalize();
Parse command line arguments.
const char * arg(const char *argn)
Get argument value.
bool has_arg(const char *argn)
Check if argument has been supplied.
Interface for logging to stderr.
Interface for logging to a specified file.
Interface for signal handling.
Thread class encapsulation of pthreads.
Fawkes library namespace.