2311.1.3
by Daniel Nichter
Change to GPLv3 license. |
1 |
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright 2011 Daniel Nichter
|
|
5 |
*
|
|
6 |
* This program is free software: you can redistribute it and/or modify
|
|
2311.1.1
by Daniel Nichter
Add query_log plugin. It's tested and documented. |
7 |
* it under the terms of the GNU General Public License as published by
|
2311.1.3
by Daniel Nichter
Change to GPLv3 license. |
8 |
* the Free Software Foundation, either version 3 of the License, or
|
9 |
* (at your option) any later version.
|
|
2311.1.1
by Daniel Nichter
Add query_log plugin. It's tested and documented. |
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
2311.1.3
by Daniel Nichter
Change to GPLv3 license. |
17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2311.1.1
by Daniel Nichter
Add query_log plugin. It's tested and documented. |
18 |
*/
|
19 |
||
2311.1.8
by Daniel Nichter
Use C++ iostream instead of Boost format. |
20 |
#include <iostream> |
21 |
#include <fstream> |
|
2311.1.1
by Daniel Nichter
Add query_log plugin. It's tested and documented. |
22 |
#include "event.h" |
23 |
||
24 |
/**
|
|
25 |
* @brief
|
|
26 |
* QueryLoggerFile implements logging to a file for the QueryLog class.
|
|
27 |
*
|
|
28 |
* @details
|
|
29 |
* This class is not a plugin (class QueryLog is the plugin class), it is
|
|
30 |
* a utility class used by the QueryLog class to do the actual logging to
|
|
31 |
* the query log file. QueryLog deals with Drizzle; this class deals with
|
|
32 |
* formatting the event and writing it to the log file.
|
|
33 |
*/
|
|
34 |
class QueryLoggerFile |
|
35 |
{
|
|
36 |
public: |
|
37 |
QueryLoggerFile(); |
|
38 |
~QueryLoggerFile(); |
|
39 |
||
40 |
/**
|
|
41 |
* @brief
|
|
42 |
* Format and write the event to the log file.
|
|
43 |
*
|
|
44 |
* @details
|
|
45 |
* This function is called by QueryLog::afterStatement(). The given
|
|
46 |
* event is a uniform struct (see event.h) and has passed filtering
|
|
47 |
* (thresholds, etc.), so it's ready to log.
|
|
48 |
*
|
|
49 |
* @param[in] event Event to log
|
|
50 |
*
|
|
51 |
* @retval true Error, event not logged
|
|
52 |
* @retval false Success, event logged
|
|
53 |
*/
|
|
54 |
bool logEvent(const event_t *event); |
|
55 |
||
56 |
/**
|
|
57 |
* @brief
|
|
58 |
* Open new log file, close old log file if successful.
|
|
59 |
*
|
|
60 |
* @details
|
|
61 |
* When global system variable query_log_file is changed, update_file()
|
|
62 |
* in module.cc is called which calls this function, passing it the new
|
|
63 |
* log file name. If opening the new log file succeeds, then the old log
|
|
64 |
* file is closed, else the old log if kept, and error is printed and
|
|
65 |
* query_log_file is not changed.
|
|
66 |
*
|
|
67 |
* @param[in] file New log file name to open
|
|
68 |
*
|
|
69 |
* @retval true Error, new log file not opened, old log file still open
|
|
70 |
* @retval false Success, old log file closed, new log file opened
|
|
71 |
*/
|
|
72 |
bool openLogFile(const char *file); |
|
73 |
||
74 |
/**
|
|
75 |
* @brief
|
|
76 |
* Close the log file.
|
|
77 |
*
|
|
78 |
* @details
|
|
79 |
* If query_log_file_enabled is false, then the log file is closed.
|
|
80 |
* However, the log file is not closed if query_log_enabled is false.
|
|
81 |
*
|
|
82 |
* @retval true Error, log file may not be closed
|
|
83 |
* @retval false Success, log file closed
|
|
84 |
*/
|
|
85 |
bool closeLogFile(); |
|
86 |
||
87 |
private: |
|
2311.1.8
by Daniel Nichter
Use C++ iostream instead of Boost format. |
88 |
std::ofstream _fh; ///< File handle for open log file |
2311.1.1
by Daniel Nichter
Add query_log plugin. It's tested and documented. |
89 |
};
|