|
a/libupnpp/log.hxx |
|
b/libupnpp/log.hxx |
|
... |
|
... |
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
16 |
*/
|
16 |
*/
|
17 |
#ifndef _LOG_H_X_INCLUDED_
|
17 |
#ifndef _LOG_H_X_INCLUDED_
|
18 |
#define _LOG_H_X_INCLUDED_
|
18 |
#define _LOG_H_X_INCLUDED_
|
19 |
|
19 |
|
|
|
20 |
#include <iostream>
|
|
|
21 |
#include <fstream>
|
|
|
22 |
#include <string>
|
|
|
23 |
|
20 |
namespace upnppdebug {
|
24 |
namespace upnppdebug {
|
21 |
typedef enum loglevels {LLDEB, LLINF, LLERR, LLFAT, LLNON} loglevels;
|
|
|
22 |
|
25 |
|
|
|
26 |
class Logger {
|
|
|
27 |
public:
|
|
|
28 |
static Logger *getTheLog(const std::string& fn);
|
|
|
29 |
std::ostream& getstream() {
|
|
|
30 |
return m_tocerr ? std::cerr : m_stream;
|
|
|
31 |
}
|
|
|
32 |
enum LogLevel {LLNON, LLFAT, LLERR, LLINF, LLDEB};
|
|
|
33 |
void setLogLevel(LogLevel level) {
|
|
|
34 |
m_loglevel = level;
|
|
|
35 |
}
|
|
|
36 |
int getloglevel() {
|
|
|
37 |
return m_loglevel;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
private:
|
|
|
41 |
bool m_tocerr;
|
23 |
extern int loglevel;
|
42 |
int m_loglevel;
|
|
|
43 |
std::ofstream m_stream;
|
|
|
44 |
|
|
|
45 |
Logger(const std::string& fn);
|
|
|
46 |
Logger(const Logger &);
|
|
|
47 |
Logger& operator=(const Logger &);
|
|
|
48 |
};
|
|
|
49 |
|
24 |
}
|
50 |
}
|
25 |
|
51 |
|
26 |
#define DEBOUT cerr
|
52 |
#define DEBOUT (upnppdebug::Logger::getTheLog("")->getstream())
|
|
|
53 |
#define LOGLEVEL (upnppdebug::Logger::getTheLog("")->getloglevel())
|
27 |
|
54 |
|
28 |
#define LOGDEB(X) { \
|
55 |
#define LOGDEB(X) { \
|
29 |
if (upnppdebug::loglevel >= upnppdebug::LLDEB) \
|
56 |
if (LOGLEVEL >= upnppdebug::Logger::LLDEB) \
|
30 |
{ \
|
57 |
{ \
|
31 |
DEBOUT << __FILE__ << ":" << __LINE__<< "::"; DEBOUT << X; \
|
58 |
DEBOUT << __FILE__ << ":" << __LINE__<< "::"; DEBOUT << X; \
|
32 |
} \
|
59 |
} \
|
33 |
}
|
60 |
}
|
34 |
|
61 |
|
35 |
#define LOGINF(X) { \
|
62 |
#define LOGINF(X) { \
|
36 |
if (upnppdebug::loglevel >= upnppdebug::LLINF) \
|
63 |
if (LOGLEVEL >= upnppdebug::Logger::LLINF) \
|
37 |
{ \
|
64 |
{ \
|
38 |
DEBOUT << __FILE__ << ":" << __LINE__<< "::"; DEBOUT << X; \
|
65 |
DEBOUT << __FILE__ << ":" << __LINE__<< "::"; DEBOUT << X; \
|
39 |
} \
|
66 |
} \
|
40 |
}
|
67 |
}
|
41 |
|
68 |
|
42 |
#define LOGERR(X) { \
|
69 |
#define LOGERR(X) { \
|
43 |
if (upnppdebug::loglevel >= upnppdebug::LLERR) \
|
70 |
if (LOGLEVEL >= upnppdebug::Logger::LLERR) \
|
44 |
{ \
|
71 |
{ \
|
45 |
DEBOUT << __FILE__ << ":" << __LINE__<< "::"; DEBOUT << X; \
|
72 |
DEBOUT << __FILE__ << ":" << __LINE__<< "::"; DEBOUT << X; \
|
46 |
} \
|
73 |
} \
|
47 |
}
|
74 |
}
|
48 |
|
75 |
|
49 |
#define LOGFAT(X) { \
|
76 |
#define LOGFAT(X) { \
|
50 |
if (upnppdebug::loglevel >= upnppdebug::LLFAT) \
|
77 |
if (LOGLEVEL >= upnppdebug::Logger::LLFAT) \
|
51 |
{ \
|
78 |
{ \
|
52 |
DEBOUT << __FILE__ << ":" << __LINE__<< "::"; DEBOUT << X; \
|
79 |
DEBOUT << __FILE__ << ":" << __LINE__<< "::"; DEBOUT << X; \
|
53 |
} \
|
80 |
} \
|
54 |
}
|
81 |
}
|
55 |
|
82 |
|