~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/query_log/file.h

  • Committer: Mark Atwood
  • Date: 2011-08-06 22:44:31 UTC
  • mfrom: (2311.1.10 query-log-plugin)
  • Revision ID: me@mark.atwood.name-20110806224431-57s1770jarqncrl7
mergeĀ lp:~daniel-nichter/drizzle/query-log-plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation, either version 3 of the License, or
 
9
 *  (at your option) any later version.
 
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
 
17
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include <iostream>
 
21
#include <fstream>
 
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:
 
88
  std::ofstream _fh;  ///< File handle for open log file
 
89
};