|
Revision 34447, 0.8 kB
(checked in by saturday06, 4 years ago)
|
|
iojasdfaodfd
|
| Line | |
|---|
| 1 | #pragma once
|
|---|
| 2 |
|
|---|
| 3 | #ifndef NDEBUG
|
|---|
| 4 |
|
|---|
| 5 | namespace mil {
|
|---|
| 6 | namespace log {
|
|---|
| 7 |
|
|---|
| 8 | using namespace std;
|
|---|
| 9 | using namespace boost;
|
|---|
| 10 |
|
|---|
| 11 | class Logger {
|
|---|
| 12 | stringstream data;
|
|---|
| 13 | string file;
|
|---|
| 14 | int line;
|
|---|
| 15 | bool will_abort;
|
|---|
| 16 | public:
|
|---|
| 17 | void operator()() const {}
|
|---|
| 18 | template <typename T>
|
|---|
| 19 | Logger& operator<<(const T& op) {
|
|---|
| 20 | data << op;
|
|---|
| 21 | return *this;
|
|---|
| 22 | }
|
|---|
| 23 | Logger(const char* file, int line, bool will_abort = false)
|
|---|
| 24 | : file(file), line(line), will_abort(will_abort) {
|
|---|
| 25 | }
|
|---|
| 26 | ~Logger() {
|
|---|
| 27 | cout << data.str() << "," << file << ":" << line << endl;
|
|---|
| 28 | //cout << data.str() << flush;
|
|---|
| 29 | if (will_abort) {
|
|---|
| 30 | cerr << "mil_abort() !" << endl;
|
|---|
| 31 | *((volatile int*)0) = -1;
|
|---|
| 32 | cerr << "SEGV suppressed !" << endl;
|
|---|
| 33 | //abort();
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 | };
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 | #endif
|
|---|
| 40 |
|
|---|