backends/quartz/quartz_log.cc

Go to the documentation of this file.
00001 /* quartz_log.cc: A logfile for quartz.
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2002 Ananova Ltd
00005  * Copyright 2002,2003,2004,2005,2006,2007 Olly Betts
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as
00009  * published by the Free Software Foundation; either version 2 of the
00010  * License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00020  * USA
00021  */
00022 
00023 #include <config.h>
00024 
00025 #include "safeerrno.h"
00026 #include "safefcntl.h"
00027 
00028 #include "quartz_log.h"
00029 #include "omdebug.h"
00030 #include "utils.h"
00031 
00032 #include <string.h>
00033 #include <time.h>
00034 
00035 #include <sys/types.h>
00036 
00037 #include "safeunistd.h"
00038 
00039 using std::string;
00040 
00041 QuartzLog::QuartzLog(string filename)
00042 {
00043     DEBUGCALL(DB, void, "QuartzLog", filename);
00044     fd = open(filename.c_str(), O_APPEND|O_WRONLY);
00045 }
00046 
00047 QuartzLog::~QuartzLog()
00048 {
00049     DEBUGCALL(DB, void, "~QuartzLog", "");
00050     if (fd != -1) {
00051         // Must ignore errors - we can't throw an exception here.
00052         (void) close(fd);
00053     }
00054 }
00055 
00056 void
00057 QuartzLog::make_entry(const string &entry) const
00058 {
00059     DEBUGCALL(DB, void, "QuartzLog::make_entry", entry);
00060     if (fd != -1) {
00061         string line(om_tostring(getpid()));
00062         line += ':';
00063         line += om_tostring(time(NULL));
00064         line += ':';
00065         line += entry;
00066         line += '\n';
00067         const char *p = line.data();
00068         ssize_t c = line.size();
00069         while (c) {
00070             ssize_t n = write(fd, p, c);
00071             if (n == -1) {
00072                 if (errno == EINTR) continue;
00073                 // FIXME: Xapian::Database*Opening*Error ?!
00074                 throw Xapian::DatabaseOpeningError("Error writing log file: " +
00075                         string(strerror(errno)));
00076             }
00077             c -= n;
00078             p += n;
00079         }
00080     }
00081 }

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.