20
20
#include <config.h>
26
23
using namespace std;
28
25
QueryLoggerFile::QueryLoggerFile()
32
// If you add something here, the number of params must match the number
33
// of values pushed to the formatter in logEvent().
36
"# session_id=%d query_id=%d rows_examined=%d rows_sent=%d tmp_tables=%d warnings=%d\n"
37
"# execution_time=%.6f lock_time=%.6f session_time=%.6f\n"
27
_fh.setf(ios::fixed, ios::floatfield);
44
31
QueryLoggerFile::~QueryLoggerFile()
49
36
bool QueryLoggerFile::logEvent(const event_t *event)
51
if (_fd == LOG_FILE_CLOSED)
58
% event->rows_examined
62
% event->execution_time
63
% event->lock_time // broken
68
string msgbuf= _formatter.str();
71
wrv= write(_fd, msgbuf.c_str(), msgbuf.length());
72
assert(wrv == msgbuf.length());
40
_fh << "# " << event->ts << "\n"
41
<< "# session_id=" << event->session_id
42
<< " query_id=" << event->query_id
43
<< " rows_examined=" << event->rows_examined
44
<< " rows_sent=" << event->rows_sent
45
<< " tmp_tables=" << event->tmp_tables
46
<< " warnings=" << event->warnings
48
<< "# execution_time=" << event->execution_time
49
<< " lock_time=" << event->lock_time
50
<< " session_time=" << event->session_time
52
<< "# error=" << event->error << "\n"
53
<< "# schema=\"" << event->schema << "\"\n"
54
<< event->query << ";\n#"
74
57
return false; // success
77
60
bool QueryLoggerFile::openLogFile(const char *file)
79
62
assert(file != NULL);
81
int new_fd= open(file, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);
66
_fh.open(file, ios::app);
83
68
return true; // error
88
70
return false; // success
91
73
bool QueryLoggerFile::closeLogFile()
93
if (not _fd == LOG_FILE_CLOSED)
94
close(_fd); // TODO: catch errors
96
82
return false; // success