OpenANN
1.1.0
An open source library for artificial neural networks.
Main Page
Classes
Files
List
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
OpenANN
io
Logger.h
Go to the documentation of this file.
1
#ifndef OPENANN_IO_LOGGER_H_
2
#define OPENANN_IO_LOGGER_H_
3
4
#include <string>
5
#include <iostream>
6
#include <sstream>
7
#include <fstream>
8
9
#ifndef NDEBUG
10
11
#define OPENANN_OUTPUT(msg) std::cout << __FILE__ << "(" << __LINE__ << "): " << msg << std::endl;
12
#define OPENANN_TRACE(msg) std::cerr << __FILE__ << "(" << __LINE__ << "): " << msg << std::endl;
13
14
#else // NDEBUG
15
16
#define OPENANN_OUTPUT(msg) std::cout << msg << std::endl;
17
#define OPENANN_TRACE(msg)
18
19
#endif // NDEBUG
20
21
#ifndef OPENANN_LOG_NAMESPACE
22
25
#define OPENANN_LOG_NAMESPACE NULL
26
#endif // OPENANN_LOG_NAMESPACE
27
28
#ifndef OPENANN_LOGLEVEL
29
33
#define OPENANN_LOGLEVEL OpenANN::Log::DEBUG
34
#endif // OPENANN_LOGLEVEL
35
40
#define OPENANN_LOG(level) \
41
if(level > OPENANN_LOGLEVEL) ; \
42
else if(level > OpenANN::Log::getLevel()) ; \
43
else OpenANN::Log().get(level, OPENANN_LOG_NAMESPACE)
44
48
#define OPENANN_DEBUG OPENANN_LOG(OpenANN::Log::DEBUG)
49
52
#define OPENANN_INFO OPENANN_LOG(OpenANN::Log::INFO)
53
56
#define OPENANN_ERROR OPENANN_LOG(OpenANN::Log::ERROR)
57
58
namespace
OpenANN
59
{
60
66
struct
FloatingPointFormatter
67
{
71
double
value
;
75
int
precision
;
76
77
FloatingPointFormatter
(
double
value
,
int
precision
)
78
: value(value), precision(precision)
79
{}
80
};
81
87
class
Log
88
{
89
public
:
90
enum
LogLevel
91
{
92
DISABLED
= 0,
93
ERROR
,
94
INFO
,
95
DEBUG
96
};
97
98
Log
();
99
virtual
~Log
();
100
101
std::ostream&
get
(
LogLevel
level,
const
char
* name_space);
102
103
static
std::ostream&
getStream
();
104
static
LogLevel
&
getLevel
();
105
106
static
void
setDisabled
();
107
static
void
setError
();
108
static
void
setInfo
();
109
static
void
setDebug
();
110
private
:
111
std::ostringstream message;
112
LogLevel
level;
113
};
114
115
121
class
Logger
122
{
123
public
:
127
static
bool
deactivate
;
131
enum
Target
132
{
133
NONE
,
134
CONSOLE
,
135
FILE
,
136
APPEND_FILE
137
}
target
;
138
139
std::string
name
;
140
std::ofstream
file
;
141
142
Logger
(
Target
target
, std::string
name
=
"Logger"
);
143
~Logger
();
148
bool
isActive
();
149
};
150
151
152
std::ostream&
operator<<
(std::ostream& os,
const
FloatingPointFormatter
& t);
153
Logger
&
operator<<
(
Logger
&
logger
,
const
FloatingPointFormatter
& t);
154
template
<
typename
T>
155
Logger
&
operator<<
(
Logger
&
logger
,
const
T
& t)
156
{
157
switch
(logger.
target
)
158
{
159
case
Logger::CONSOLE
:
160
std::cout << t << std::flush;
161
break
;
162
case
Logger::APPEND_FILE
:
163
case
Logger::FILE
:
164
logger.
file
<< t << std::flush;
165
break
;
166
default
:
// do not log
167
break
;
168
}
169
return
logger
;
170
}
171
172
}
// namespace OpenANN
173
174
#endif // OPENANN_IO_LOGGER_H_
Generated on Wed Jul 9 2014 08:57:52 for OpenANN by
1.8.4