Update of /cvsroot/pclasses/pclasses2/plugins/LogTarget/File
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30732/plugins/LogTarget/File
Added Files:
Makefile.am FileLogTarget.cpp
Log Message:
- Added FileLogTarget plugin
--- NEW FILE: FileLogTarget.cpp ---
/***************************************************************************
* Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH *
* cp...@se... *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "pclasses/Plugin/Plugin.h"
#include "pclasses/IO/IOStream.h"
#include "pclasses/System/File.h"
#include "pclasses/App/LogTarget.h"
#include <iostream>
using namespace P;
using namespace P::IO;
using namespace P::System;
using namespace P::App;
using namespace std;
class FileLogTarget: public LogTarget {
public:
FileLogTarget()
: _file(), _out(0)
{
}
~FileLogTarget() throw()
{
if(_out)
delete _out;
}
void open(const URL& url) throw(IOError)
{
_file.open(url.path(), IODevice::Write, IODevice::OpenCreate,
IODevice::AllowRead);
_out = new IOStream(_file);
}
void close() throw(IOError)
{
_file.close();
delete _out;
}
void reload() throw(IOError)
{
}
void output(const LogMessage& msg) throw(IOError)
{
(*_out) << msg.when() << ' ' << msg.level2Str(msg.level()) << ' ' << msg.msg().utf8() << endl;
}
bool valid() const throw()
{
return _file.valid();
}
private:
File _file;
IOStream* _out;
};
PLUGIN_REGISTER_TYPE(LogTarget, FileLogTarget);
PLUGIN_REGISTER_ALIAS(LogTarget, File, FileLogTarget);
--- NEW FILE: Makefile.am ---
INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include $(all_includes)
METASOURCES = AUTO
pkglib_LTLIBRARIES = FileLogTarget.la
FileLogTarget_la_SOURCES = FileLogTarget.cpp
FileLogTarget_la_LDFLAGS = -module -avoid-version
FileLogTarget_la_LIBADD = $(top_builddir)/src/libpclasses.la \
$(top_builddir)/src/App/libpclasses_app.la
|