forked from gsingh93/slim-display-manager
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
log.h
49 lines (40 loc) · 817 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
45
46
47
48
49
#ifndef _LOG_H_
#define _LOG_H_
#ifdef USE_CONSOLEKIT
#include "Ck.h"
#endif
#ifdef USE_PAM
#include "PAM.h"
#endif
#include "const.h"
#include <fstream>
#include <iostream>
using namespace std;
static class LogUnit
{
ofstream logFile;
inline ostream & getStream() { return logFile.is_open() ? logFile : cerr; }
public:
bool openLog(const char * filename);
void closeLog();
~LogUnit() { closeLog(); }
template <typename Type> LogUnit & operator<<(const Type & text)
{
getStream() << text;
getStream().flush();
return *this;
}
LogUnit & operator<<(ostream & (*fp)(ostream &))
{
getStream() << fp;
getStream().flush();
return *this;
}
LogUnit & operator<<(ios_base & (*fp)(ios_base &))
{
getStream() << fp;
getStream().flush();
return *this;
}
} logStream;
#endif /* _LOG_H_ */