-
Notifications
You must be signed in to change notification settings - Fork 1
/
Log.h
executable file
·44 lines (41 loc) · 888 Bytes
/
Log.h
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
39
40
41
42
43
44
#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <boost/format.hpp>
using namespace std;
enum TOKEN{ _endl_ };
class Log
{
public:
void set_level(int level = 0, string log_file = "");
template<typename T>
Log& operator<<(const T& t);
string time();
private:
//level:
// 0: output to log file,
// 1: output to console
int level;
int count;
fstream fout;
};
template<typename T>
Log& Log::operator<< (const T& t)
{
if (this->count == 0)
{
this->fout << "[" << this->time() << "] ";
}
if (typeid(t).name() == typeid(_endl_).name())
{
this->count = 0;
this->level == 0 ? this->fout << endl : cout << endl;
}
else
{
++this->count;
this->level == 0 ? this->fout << t: cout << t;
}
return *this;
}