Drizzled Public API Documentation

file.cc
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright 2011 Daniel Nichter
00005  *
00006  *  This program is free software: you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation, either version 3 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #include <config.h>
00021 #include "file.h"
00022 
00023 using namespace std;
00024 
00025 QueryLoggerFile::QueryLoggerFile()
00026 {
00027   _fh.setf(ios::fixed, ios::floatfield);
00028   _fh.precision(6);
00029 }
00030 
00031 QueryLoggerFile::~QueryLoggerFile()
00032 {
00033   closeLogFile();
00034 }
00035 
00036 bool QueryLoggerFile::logEvent(const event_t *event)
00037 {
00038   if (_fh.is_open())
00039   {
00040     _fh << "# start_ts=" << event->ts
00041         << "\n"
00042         << "# session_id="     << event->session_id
00043         <<  " query_id="       << event->query_id
00044         <<  " rows_examined="  << event->rows_examined
00045         <<  " rows_sent="      << event->rows_sent
00046         <<  " tmp_tables="     << event->tmp_tables
00047         <<  " warnings="       << event->warnings
00048         << "\n"
00049         << "# execution_time=" << event->execution_time
00050         <<  " lock_time="      << event->lock_time
00051         <<  " session_time="   << event->session_time
00052         << "\n"
00053         << "# error=" << event->error << "\n"
00054         << "# schema=\"" << event->schema << "\"\n"
00055         << event->query << ";\n#"
00056         << endl;
00057   }
00058   return false; // success
00059 }
00060 
00061 bool QueryLoggerFile::openLogFile(const char *file)
00062 {
00063   closeLogFile();
00064 
00065   _fh.open(file, ios::app);
00066   if (_fh.fail())
00067     return true; // error
00068 
00069   return false; // success
00070 }
00071 
00072 bool QueryLoggerFile::closeLogFile()
00073 {
00074   if (_fh.is_open())
00075   {
00076     _fh.close();
00077     if (_fh.fail())
00078       return true;  // error
00079   }
00080 
00081   return false;  // success
00082 }