I have only compiled and tested this to some extent with Visual Studio 6.0 with a very simple setup. In particular, I put the win32odsappender.h into include/log4cxx/nt as it's a Win32 component.
I'm new at this log4cxx stuff, so please be on the lookout for side-effects in you own configurations!
Regards,
DP
/* * Copyright (c) 2004 Leslie Spiro. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #ifdef WIN32
#include <windows.h>
#undef ERROR
#include <log4cxx/nt/win32odsappender.h>
#include <log4cxx/spi/loggingevent.h>
using namespace log4cxx;
using namespace log4cxx::spi;
using namespace log4cxx::helpers;
IMPLEMENT_LOG4CXX_OBJECT(Win32ODSAppender)
Win32ODSAppender::Win32ODSAppender()
{
}
Win32ODSAppender::Win32ODSAppender(const LayoutPtr& layout)
{
this->layout = layout;
}
Win32ODSAppender::~Win32ODSAppender()
{
finalize();
}
void Win32ODSAppender::close()
{
}
void Win32ODSAppender::append(const LoggingEventPtr& event)
{
StringBuffer oss;
layout->format(oss, event);
String sz = oss.str();
String::size_type len = sz.size();
if (len > 0)
{
// Replace all "\n" with "\r\n" pairs
const char *pString = sz.c_str();
if ((len < 2) || (pString[len - 1] != '\n'))
{
sz.append("\r\n");
pString = sz.c_str();
}
OutputDebugString(pString);
}
}
#endif // WIN32
/* * Copyright (c) 2004 Leslie Spiro. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #ifndef _LOG4CXX_WIN32_ODS_APPENDER_HEADER_ #define _LOG4CXX_WIN32_ODS_APPENDER_HEADER_ #include <log4cxx/appenderskeleton.h> namespace log4cxx { /** * Appends log events to Win32 OutputDebugString Kernel API */ class LOG4CXX_EXPORT Win32ODSAppender : public AppenderSkeleton { public: DECLARE_LOG4CXX_OBJECT(Win32ODSAppender) BEGIN_LOG4CXX_CAST_MAP() LOG4CXX_CAST_ENTRY(Win32ODSAppender) LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) END_LOG4CXX_CAST_MAP() Win32ODSAppender(); Win32ODSAppender(const LayoutPtr& layout); virtual ~Win32ODSAppender(); virtual void close(); bool requiresLayout() const { return true; } protected: virtual void append(const spi::LoggingEventPtr& event); }; // class Win32ODSAppender }; // namespace log4cxx #endif //_LOG4CXX_WIN32_ODS_APPENDER_HEADER_
