1 /*
2 * (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>
3 * economic rights: Technische Universität Dresden (Germany)
4 *
5 * This file is part of TUD:OS and distributed under the terms of the
6 * GNU General Public License 2.
7 * Please see the COPYING-GPL-2 file for details.
8 *
9 * As a special exception, you may use this file as part of a free software
10 * library without restriction. Specifically, if other files instantiate
11 * templates or use macros or inline functions from this file, or you compile
12 * this file and link it with other files to produce an executable, this
13 * file does not by itself cause the resulting executable to be covered by
14 * the GNU General Public License. This exception does not however
15 * invalidate any other reasons why the executable file might be covered by
16 * the GNU General Public License.
17 */
18 #include <l4/re/util/debug>
19
20 #include <stdarg.h>
21 #include <stdio.h>
22
23 namespace L4Re { namespace Util {
24
25 static FILE *&out = stdout;
26 #ifndef NDEBUG
27 unsigned long Dbg::level = 1;
28
29 void
tag() const30 Dbg::tag() const
31 {
32 if (!_component)
33 return;
34 if (_subsys)
35 cprintf("%s[%s]: ", _component, _subsys);
36 else
37 cprintf("%s: ", _component);
38 }
39
40
41 int
printf_impl(char const * fmt,...) const42 Dbg::printf_impl(char const *fmt, ...) const
43 {
44 tag();
45
46 int n;
47 va_list args;
48
49 va_start (args, fmt);
50 n = vfprintf (out, fmt, args);
51 va_end (args);
52
53 return n;
54 }
55
56 int
cprintf_impl(char const * fmt,...) const57 Dbg::cprintf_impl(char const *fmt, ...) const
58 {
59 int n;
60 va_list args;
61
62 va_start (args, fmt);
63 n = vfprintf (out, fmt, args);
64 va_end (args);
65
66 return n;
67 }
68 #endif /* NDEBUG */
69
70
71 char const *const Err::levels[] =
72 { "ERROR: ", "FATAL: " };
73
74 int
printf(char const * fmt,...) const75 Err::printf(char const *fmt, ...) const
76 {
77 tag();
78
79 int n;
80 va_list args;
81
82 va_start (args, fmt);
83 n = vfprintf (out, fmt, args);
84 va_end (args);
85
86 return n;
87 }
88
89 int
cprintf(char const * fmt,...) const90 Err::cprintf(char const *fmt, ...) const
91 {
92 int n;
93 va_list args;
94
95 va_start (args, fmt);
96 n = vfprintf (out, fmt, args);
97 va_end (args);
98
99 return n;
100 }
101
102 }}
103