libopenraw
trace.cpp
1 /*
2  * libopenraw - trace.cpp
3  *
4  * Copyright (C) 2006-2014 Hubert Figuiere
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <stdarg.h>
22 #include <stdio.h>
23 
24 #include <iostream>
25 
26 #include <libopenraw/debug.h>
27 
28 #include "trace.hpp"
29 
30 namespace Debug {
31 
32 int Trace::debugLevel = NOTICE;
33 
34 void log(debug_level level, const char *fmt, ...)
35 {
36  if (level > Trace::debugLevel) {
37  return;
38  }
39 
40  va_list marker;
41 
42  va_start(marker, fmt);
43  vfprintf(stderr, fmt, marker);
44 
45  va_end(marker);
46 }
47 
48 void Trace::setDebugLevel(debug_level lvl)
49 {
50  debugLevel = lvl;
51 }
52 
53 void Trace::print(int i)
54 {
55  std::cerr << i << " ";
56 }
57 
58 Trace & Trace::operator<<(int i)
59 {
60  if (m_level <= debugLevel) {
61  std::cerr << i;
62  }
63  return *this;
64 }
65 
66 Trace & Trace::operator<<(const char * s)
67 {
68  if (m_level <= debugLevel) {
69  std::cerr << s;
70  }
71  return *this;
72 }
73 
74 Trace & Trace::operator<<(void *p)
75 {
76  if (m_level <= debugLevel) {
77  std::cerr << p;
78  }
79  return *this;
80 }
81 
82 Trace & Trace::operator<<(const std::string & s)
83 {
84  if (m_level <= debugLevel) {
85  std::cerr << s;
86  }
87  return *this;
88 }
89 
90 }
91 
92 /*
93  Local Variables:
94  mode:c++
95  c-file-style:"stroustrup"
96  c-file-offsets:((innamespace . 0))
97  tab-width:2
98  c-basic-offset:2
99  indent-tabs-mode:nil
100  fill-column:80
101  End:
102 */
Definition: trace.cpp:30