1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2011 Daniel Nichter
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
QueryLoggerFile::QueryLoggerFile()
31
// If you add something here, the number of params must match the number
32
// of values pushed to the formatter in logEvent().
35
"# session_id=%d query_id=%d rows_examined=%d rows_sent=%d tmp_tables=%d warnings=%d\n"
36
"# execution_time=%.6f lock_time=%.6f session_time=%.6f\n"
43
QueryLoggerFile::~QueryLoggerFile()
48
bool QueryLoggerFile::logEvent(const event_t *event)
50
if (_fd == LOG_FILE_CLOSED)
57
% event->rows_examined
61
% event->execution_time
62
% event->lock_time // broken
67
string msgbuf= _formatter.str();
70
wrv= write(_fd, msgbuf.c_str(), msgbuf.length());
71
assert(wrv == msgbuf.length());
73
return false; // success
76
bool QueryLoggerFile::openLogFile(const char *file)
80
int new_fd= open(file, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);
87
return false; // success
90
bool QueryLoggerFile::closeLogFile()
92
if (not _fd == LOG_FILE_CLOSED)
93
close(_fd); // TODO: catch errors
95
return false; // success