-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlog_file.h
More file actions
55 lines (39 loc) · 1018 Bytes
/
Copy pathlog_file.h
File metadata and controls
55 lines (39 loc) · 1018 Bytes
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
50
51
52
53
54
55
#ifndef __YDX_LOG_FILE_H__
#define __YDX_LOG_FILE_H__
#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
#include <string>
#include "ydx_mutex.h"
namespace ydx
{
class AppendFile;
class LogFile : boost::noncopyable
{
public:
LogFile(
size_t rollSize = 1024 * 1024 * 1,
const std::string& basename ="",
bool threadSafe = true,
int flushInterval = 3,
int checkEveryN = 10000);
~LogFile();
void append(const char* logline, int len);
void flush();
bool rollFile();
private:
void append_unlocked(const char* logline, int len);
static std::string getLogFileName(const std::string& basename, time_t* now);
std::string basename_;
const size_t rollSize_;
const int flushInterval_;
const int checkEveryN_;
int count_;
boost::scoped_ptr<MutexLock> mutex_;
time_t startOfPeriod_;
time_t lastRoll_;
time_t lastFlush_;
boost::scoped_ptr<AppendFile> file_;
const static int kRollPerSeconds_ = 60*60*24;
};
}
#endif