Fawkes API Fawkes Development Version
qa_logger.cpp
1
2/***************************************************************************
3 * qa_logger.cpp - QA for Logger
4 *
5 * Generated: Wed Jan 17 14:19:45 2007
6 * Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24// Do not include in api reference
25///@cond QA
26
27#include <core/threading/thread.h>
28#include <utils/logging/console.h>
29#include <utils/logging/logger.h>
30#include <utils/logging/multi.h>
31#include <utils/system/signal.h>
32
33#include <cstdio>
34
35using namespace fawkes;
36
37class LoggerQAThread : public Thread
38{
39public:
40 LoggerQAThread(const char *name, Logger *logger) : Thread(name)
41 {
42 this->logger = logger;
43 i = 0;
44 }
45
46 virtual void
47 loop()
48 {
49 ++i;
50 printf("%s: Testing: %i\n", name(), i);
51 logger->log_info(name(), "Testing: %i", i);
52 }
53
54private:
55 unsigned int i;
56 Logger * logger;
57};
58
59class LoggerQAMain : public SignalHandler
60{
61public:
62 LoggerQAMain()
63 {
64 cl = ml = NULL;
65 t1 = t2 = t3 = t4 = t5 = t6 = NULL;
66 }
67
68 ~LoggerQAMain()
69 {
70 delete t1;
71 delete t2;
72 delete t3;
73 delete t4;
74 delete t5;
75 delete t6;
76 // also deletes cl!
77 delete ml;
78 }
79
80 virtual void
81 handle_signal(int signum)
82 {
83 printf("Signal received, cancelling threads\n");
84 t1->cancel();
85 t2->cancel();
86 t3->cancel();
87 t4->cancel();
88 t5->cancel();
89 t6->cancel();
90 printf("Threads cancelled\n");
91 }
92
93 void
94 run()
95 {
96 cl = new ConsoleLogger();
97 ml = new MultiLogger(cl);
98
99 t1 = new LoggerQAThread("L-1-", ml);
100 t2 = new LoggerQAThread("L-2-", ml);
101 t3 = new LoggerQAThread("L-3-", ml);
102 t4 = new LoggerQAThread("L-4-", ml);
103 t5 = new LoggerQAThread("L-5-", ml);
104 t6 = new LoggerQAThread("L-6-", ml);
105
106 t1->start();
107 t2->start();
108 t3->start();
109 t4->start();
110 t5->start();
111 t6->start();
112 t1->join();
113 t2->join();
114 t3->join();
115 t4->join();
116 t5->join();
117 t6->join();
118 }
119
120private:
121 Logger * cl;
122 Logger * ml;
123 LoggerQAThread *t1;
124 LoggerQAThread *t2;
125 LoggerQAThread *t3;
126 LoggerQAThread *t4;
127 LoggerQAThread *t5;
128 LoggerQAThread *t6;
129};
130
131int
132main(int argc, char **argv)
133{
134 /*
135 ConsoleLogger cl;
136
137 Exception e("Test Exception");
138
139 cl.log_debug("QA", "DEBUG test output %i", 1);
140 cl.log_info("QA", "DEBUG test output %i", 2);
141 cl.log_warn("QA", "DEBUG test output %i", 3);
142 cl.log_error("QA", "DEBUG test output %i", 4);
143
144 cl.log_debug("QA", e);
145 cl.log_info("QA", e);
146 cl.log_warn("QA", e);
147 cl.log_error("QA", e);
148
149 ConsoleLogger *clp = new ConsoleLogger();
150
151 clp->log_debug("QA", "DEBUG test output %i", 1);
152 clp->log_info("QA", "DEBUG test output %i", 2);
153 clp->log_warn("QA", "DEBUG test output %i", 3);
154 clp->log_error("QA", "DEBUG test output %i", 4);
155
156 clp->log_debug("QA", e);
157 clp->log_info("QA", e);
158 clp->log_warn("QA", e);
159 clp->log_error("QA", e);
160
161 LoggerTestThread *tt = new LoggerTestThread(clp);
162 tt->start();
163 tt->join();
164 delete tt;
165
166 delete clp;
167 */
168
169 LoggerQAMain main;
170 SignalManager::register_handler(SIGINT, &main);
171 main.run();
172 SignalManager::finalize();
173
174 return 0;
175}
176
177/// @endcond
Interface for logging to stderr.
Definition: console.h:37
Interface for logging.
Definition: logger.h:42
Log through multiple loggers.
Definition: multi.h:35
virtual void log_info(const char *component, const char *format,...)
Log informational message.
Definition: multi.cpp:195
Interface for signal handling.
Definition: signal.h:36
Thread class encapsulation of pthreads.
Definition: thread.h:46
Fawkes library namespace.