1 #ifndef _ACLOGGER_H
2 #define _ACLOGGER_H
3
4 #include "config.h"
5 #include "meta.h"
6 #include "acbuf.h"
7
8 namespace acng
9 {
10
11 #ifdef DEBUG
12
13 struct t_logger
14 {
15 t_logger(const char *szFuncName, const void * ptr); // starts the logger, shifts stack depth
16 ~t_logger();
17 tSS & GetFmter();
18 void Write(const char *pFile = nullptr, unsigned int nLine = 0);
19 private:
20 tSS m_strm;
21 pthread_t m_id;
22 unsigned int m_nLevel;
23 const char * m_szName;
24 uintptr_t callobj;
25 // don't copy
26 t_logger(const t_logger&);
27 t_logger operator=(const t_logger&);
28 };
29 #define USRDBG(msg) LOG(msg)
30 #else
31 // print some extra things when user wants debug with non-debug build
32 #define USRDBG(msg) { if(cfg::debug & log::LOG_DEBUG) {log::err( tSS()<<msg); } }
33 #endif
34
35 namespace log
36 {
37
38 enum ETransferType
39 : char
40 {
41 INDATA = 'I', OUTDATA = 'O', ERRORRQ = 'E'
42 };
43
44 enum ELogFlags
45 : uint8_t
46 {
47 LOG_FLUSH = 1, LOG_MORE = 2, LOG_DEBUG = 4
48 };
49
50 // access internal counters
51 std::pair<off_t, off_t> GetCurrentCountersInOut();
52 void ResetOldCounters();
53 std::pair<off_t, off_t> GetOldCountersInOut(bool calcIncomming = true, bool calcOutgoing = true);
54
55 bool open();
56 void close(bool bReopen);
57 void transfer(uint64_t bytesIn, uint64_t bytesOut, cmstring& sClient, cmstring& sPath,
58 bool bAsError);
59 void err(const char *msg, const char *client = nullptr);
60 void misc(const mstring & sLine, const char cLogType = 'M');
err(cmstring & msg)61 inline void err(cmstring &msg)
62 {
63 err(msg.c_str());
64 }
err(const tSS & msg)65 inline void err(const tSS& msg)
66 {
67 err(msg.c_str());
68 }
69 void flush();
70
71 void GenerateReport(mstring &);
72
73 class tRowData
74 {
75 public:
76 uint64_t byteIn, byteOut;
77 unsigned long reqIn, reqOut;
78 time_t from, to;
tRowData()79 tRowData() :
80 byteIn(0), byteOut(0), reqIn(0), reqOut(0), from(0), to(0)
81 {
82 }
83 ;
84 /*
85 tRowData(const tRowData &a) :
86 byteIn(a.byteIn), byteOut(a.byteOut),
87 reqIn(a.reqIn), reqOut(a.reqOut),
88 from(a.from), to(a.to)
89 {
90 };
91 */
92 private:
93 // tRowData & operator=(const tRowData &a);
94 };
95
96 mstring GetStatReport();
97
98 }
99
100 //#define TIMEFORMAT "%a %d/%m"
101 #define TIMEFORMAT "%Y-%m-%d %H:%M"
102
103 }
104
105 #endif
106