File: logger.h

package info (click to toggle)
literki 0.0.0+20100113.git1da40724-1.2
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 3,444 kB
  • ctags: 1,153
  • sloc: cpp: 5,263; makefile: 72
file content (38 lines) | stat: -rw-r--r-- 1,071 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef LOGGER_H_
#define LOGGER_H_

#include <iostream>
#include <string>

#define CHECK(expr) (((expr) == 0) ? LOG(FATAL) << __FILE__ << ": "<<__LINE__<< " : "<< __PRETTY_FUNCTION__<< ": check failed: "<< #expr<<": ": LOG(DEV_NULL))
#define CHECK_EQ(expr, val) CHECK_EQ_FUN(expr,val,#expr,#val,__FILE__,__LINE__,__PRETTY_FUNCTION__)

enum LogType {
  INFO,
  FATAL,
  DEV_NULL,
};


class Logger: public std::ostream {
  public:
  ~Logger();
  Logger(const Logger& l);
  Logger& operator << (const char *);
  Logger& operator << (const std::string&);
  Logger& operator << (int);
  Logger& operator << (double);
  private:
  friend Logger LOG(LogType t);
  Logger(LogType t);
  LogType type_;
};
Logger LOG(LogType t);

template <typename A, typename B>
Logger CHECK_EQ_FUN(A expr, B val, const char* expr_str, const char* val_str , const char* file, int line, const char* func){
  return expr!=val ? LOG(FATAL) << file<<": "<<line<<": "<<func<<": equality check failed: "<<expr_str<<"="<<expr<<" != "<<val_str<<"="<<val<<" :" : LOG(DEV_NULL);
}


#endif /*LOGGER_H_*/