|
a/libupnpp/log.hxx |
|
b/libupnpp/log.hxx |
1 |
/* Copyright (C) 2014 J.F.Dockes
|
1 |
#include "log.h"
|
2 |
* This program is free software; you can redistribute it and/or modify
|
|
|
3 |
* it under the terms of the GNU General Public License as published by
|
|
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
5 |
* (at your option) any later version.
|
|
|
6 |
*
|
|
|
7 |
* This program is distributed in the hope that it will be useful,
|
|
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
10 |
* GNU General Public License for more details.
|
|
|
11 |
*
|
|
|
12 |
* You should have received a copy of the GNU General Public License
|
|
|
13 |
* along with this program; if not, write to the
|
|
|
14 |
* Free Software Foundation, Inc.,
|
|
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
16 |
*/
|
|
|
17 |
#ifndef _LOG_H_X_INCLUDED_
|
|
|
18 |
#define _LOG_H_X_INCLUDED_
|
|
|
19 |
|
|
|
20 |
#include <fstream> // for ofstream
|
|
|
21 |
#include <iostream> // for cerr, ostream
|
|
|
22 |
#include <string> // for string
|
|
|
23 |
|
|
|
24 |
namespace UPnPP {
|
|
|
25 |
|
|
|
26 |
class Logger {
|
|
|
27 |
public:
|
|
|
28 |
/** Initialize logging to file name. Use "stderr" for stderr output */
|
|
|
29 |
static Logger *getTheLog(const std::string& fn);
|
|
|
30 |
std::ostream& getstream() {
|
|
|
31 |
return m_tocerr ? std::cerr : m_stream;
|
|
|
32 |
}
|
|
|
33 |
enum LogLevel {LLNON, LLFAT, LLERR, LLINF, LLDEB, LLDEB1};
|
|
|
34 |
void setLogLevel(LogLevel level) {
|
|
|
35 |
m_loglevel = level;
|
|
|
36 |
}
|
|
|
37 |
int getloglevel() {
|
|
|
38 |
return m_loglevel;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
private:
|
|
|
42 |
bool m_tocerr;
|
|
|
43 |
int m_loglevel;
|
|
|
44 |
std::ofstream m_stream;
|
|
|
45 |
|
|
|
46 |
Logger(const std::string& fn);
|
|
|
47 |
Logger(const Logger &);
|
|
|
48 |
Logger& operator=(const Logger &);
|
|
|
49 |
};
|
|
|
50 |
|
|
|
51 |
#define DEBOUT (Logger::getTheLog("")->getstream())
|
|
|
52 |
#ifndef LOCAL_LOGINC
|
|
|
53 |
#define LOCAL_LOGINC 0
|
|
|
54 |
#endif
|
|
|
55 |
#define LOGLEVEL (Logger::getTheLog("")->getloglevel()+LOCAL_LOGINC)
|
|
|
56 |
|
|
|
57 |
#define LOGDEB1(X) { \
|
|
|
58 |
if (LOGLEVEL >= Logger::LLDEB1) \
|
|
|
59 |
{ \
|
|
|
60 |
DEBOUT << __FILE__ << ":" << __LINE__<< "::"; DEBOUT << X; \
|
|
|
61 |
} \
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
#define LOGDEB(X) { \
|
|
|
65 |
if (LOGLEVEL >= Logger::LLDEB) \
|
|
|
66 |
{ \
|
|
|
67 |
DEBOUT << __FILE__ << ":" << __LINE__<< "::"; DEBOUT << X; \
|
|
|
68 |
} \
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
#define LOGINF(X) { \
|
|
|
72 |
if (LOGLEVEL >= Logger::LLINF) \
|
|
|
73 |
{ \
|
|
|
74 |
DEBOUT << __FILE__ << ":" << __LINE__<< "::"; DEBOUT << X; \
|
|
|
75 |
} \
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
#define LOGERR(X) { \
|
|
|
79 |
if (LOGLEVEL >= Logger::LLERR) \
|
|
|
80 |
{ \
|
|
|
81 |
DEBOUT << __FILE__ << ":" << __LINE__<< "::"; DEBOUT << X; \
|
|
|
82 |
} \
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
#define LOGFAT(X) { \
|
|
|
86 |
if (LOGLEVEL >= Logger::LLFAT) \
|
|
|
87 |
{ \
|
|
|
88 |
DEBOUT << __FILE__ << ":" << __LINE__<< "::"; DEBOUT << X; \
|
|
|
89 |
} \
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
} // namespace UPnPP
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
#endif /* _LOG_H_X_INCLUDED_ */
|
|
|