file_appender.cpp

Go to the documentation of this file.
00001 
00008 /**************************************************************************
00009 
00010    begin                : Thu Sep 13 2007
00011    copyright            : (C) 2007 by Ewald Arnold
00012    email                : log4sendpp at ewald-arnold dot de
00013 
00014    This program is free software; you can redistribute it and/or modify
00015    it under the terms of the GNU Lesser General Public License as
00016    published by the Free Software Foundation; either version 2 of the License,
00017    or (at your option) any later version.
00018 
00019    This program is distributed in the hope that it will be useful,
00020    but WITHOUT ANY WARRANTY; without even the implied warranty of
00021    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022    GNU General Public License for more details.
00023 
00024    You should have received a copy of the GNU Lesser General Public License
00025    along with this program; if not, write to the Free Software
00026    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00027 
00028  **/
00029 
00031 #define LOG4SENDPP_NEED_EXPORTS
00032 #include <log4sendpp/log4sendpp.h> // always first
00033 
00034 #include <fstream>
00035 
00036 #include <log4sendpp/file_appender.h>
00037 #include <log4sendpp/formatter.h>
00038 
00039 
00040 LOG4SENDPP_NS_START
00041 
00042 
00043 LOG4SENDPP_API_IMPL0 FileAppender::FileAppender(Formatter *formatter,
00044                                                 const LOG4SENDPP_STD_NS::string &in_name)
00045   : Appender(formatter)
00046   , filename(in_name)
00047 {
00048 }
00049 
00050 
00051 LOG4SENDPP_API_IMPL(void) FileAppender::append (Logger::Level level,
00052                                                 LOG4SENDPP_STD_NS::string msg,
00053                                                 LOG4SENDPP_STD_NS::string category,
00054                                                 LOG4SENDPP_INT64 stamp,
00055                                                 const LocationInformation *info,
00056                                                 const Logger::DiagnosticInformation *diaginfo)
00057 {
00058   Formatter *formatter = getFormatter();
00059   if (formatter)
00060   {
00061     LOG4SENDPP_STD_NS::vector<LOG4SENDPP_STD_NS::string> msgs = formatter->format(level, msg, category, stamp, info, diaginfo);
00062 
00063     LOG4SENDPP_STD_NS::string s;
00064     for (unsigned i = 0; i < msgs.size(); ++i)
00065        s += msgs[i] + "\n";
00066 
00067     writeString(s);
00068   }
00069 }
00070 
00071 
00072 LOG4SENDPP_API_IMPL(void) FileAppender::writeString(const LOG4SENDPP_STD_NS::string &data)
00073 {
00074    LOG4SENDPP_STD_NS::ofstream ofs(filename.c_str(), LOG4SENDPP_STD_NS::ios::app);
00075    ofs << data;
00076 }
00077 
00078 
00079 LOG4SENDPP_API_IMPL(bool) FileAppender::isWorking() const
00080 {
00081    return true;
00082 }
00083 
00084 
00085 LOG4SENDPP_NS_END
00086 

Generated on Sat Nov 24 14:41:22 2007 for log4sendpp by  doxygen 1.5.3