You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ca...@apache.org on 2004/10/22 17:13:36 UTC
cvs commit: logging-log4cxx/tests/src/util filter.h
carnold 2004/10/22 08:13:36
Modified: include/log4cxx/db odbcappender.h
include/log4cxx/helpers exception.h socketimpl.h
include/log4cxx/spi loggingevent.h
src class.cpp datagramsocket.cpp properties.cpp
socketimpl.cpp
tests/src/util filter.h
Log:
LOGCXX-31: Missing const on Exception::getMessage
Revision Changes Path
1.14 +36 -36 logging-log4cxx/include/log4cxx/db/odbcappender.h
Index: odbcappender.h
===================================================================
RCS file: /home/cvs/logging-log4cxx/include/log4cxx/db/odbcappender.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- odbcappender.h 13 Aug 2004 12:27:46 -0000 1.13
+++ odbcappender.h 22 Oct 2004 15:13:36 -0000 1.14
@@ -1,26 +1,26 @@
/*
* Copyright 2003,2004 The Apache Software Foundation.
- *
+ *
* 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_DB_ODBC_APPENDER_H
#define _LOG4CXX_DB_ODBC_APPENDER_H
#include <log4cxx/portability.h>
#ifdef LOG4CXX_HAVE_ODBC
-
+
#include <log4cxx/helpers/exception.h>
#include <log4cxx/appenderskeleton.h>
#include <log4cxx/spi/loggingevent.h>
@@ -40,7 +40,7 @@
{
public:
SQLException(int code) : code(code) {}
- virtual String getMessage() { return String(); }
+ virtual String getMessage() const { return String(); }
int code;
};
@@ -101,17 +101,17 @@
* URL of the DB for default connection handling
*/
String databaseURL;
-
+
/**
* User to connect as for default connection handling
*/
String databaseUser;
-
+
/**
* User to use for default connection handling
*/
String databasePassword;
-
+
/**
* Connection used by default. The connection is opened the first time it
* is needed and then held open until the appender is closed (usually at
@@ -121,7 +121,7 @@
*/
SQLHDBC connection;
SQLHENV env;
-
+
/**
* Stores the string given to the pattern layout for conversion into a SQL
* statement, eg: insert into LogTable (Thread, File, Message) values
@@ -132,19 +132,19 @@
* Also see PatternLayout.
*/
String sqlStatement;
-
+
/**
* size of LoggingEvent buffer before writting to the database.
* Default is 1.
*/
size_t bufferSize;
-
+
/**
* ArrayList holding the buffer of Logging Events.
*/
std::list<spi::LoggingEventPtr> buffer;
-
- public:
+
+ public:
DECLARE_LOG4CXX_OBJECT(ODBCAppender)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(ODBCAppender)
@@ -153,7 +153,7 @@
ODBCAppender();
virtual ~ODBCAppender();
-
+
/**
Set options
*/
@@ -163,7 +163,7 @@
* Adds the event to the buffer. When full the buffer is flushed.
*/
void append(const spi::LoggingEventPtr& event);
-
+
/**
* By default getLogStatement sends the event to the required Layout object.
* The layout will format the given pattern into a workable SQL string.
@@ -184,7 +184,7 @@
* accessed in an override of this method.
* */
void execute(const String& sql) /*throw(SQLException)*/;
-
+
/**
* Override this to return the connection to a pool, or to clean up the
* resource.
@@ -193,7 +193,7 @@
* is closed (typically when garbage collected).
*/
virtual void closeConnection(SQLHDBC con);
-
+
/**
* Override this to link with your connection pooling system.
*
@@ -201,14 +201,14 @@
* until the object is garbage collected.
*/
virtual SQLHDBC getConnection() /*throw(SQLException)*/;
-
+
/**
* Closes the appender, flushing the buffer first then closing the default
* connection if it is open.
*/
public:
virtual void close();
-
+
/**
* loops through the buffer of LoggingEvents, gets a
* sql string from getLogStatement() and sends it to execute().
@@ -217,13 +217,13 @@
* If a statement fails the LoggingEvent stays in the buffer!
*/
void flushBuffer();
-
+
/**
* ODBCAppender requires a layout.
* */
virtual bool requiresLayout() const
{ return true; }
-
+
/**
* Set pre-formated statement eg: insert into LogTable (msg) values ("%m")
*/
@@ -234,34 +234,34 @@
*/
inline const String& getSql() const
{ return sqlStatement; }
-
-
+
+
inline void setUser(const String& user)
{ databaseUser = user; }
-
-
+
+
inline void setURL(const String& url)
{ databaseURL = url; }
-
-
+
+
inline void setPassword(const String& password)
{ databasePassword = password; }
-
-
+
+
inline void setBufferSize(size_t newBufferSize)
{ bufferSize = newBufferSize; }
-
+
inline const String& getUser() const
{ return databaseUser; }
-
-
+
+
inline const String& getURL() const
{ return databaseURL; }
-
-
+
+
inline const String& getPassword() const
{ return databasePassword; }
-
+
inline size_t getBufferSize() const
{ return bufferSize; }
}; // class ODBCAppender
1.11 +12 -10 logging-log4cxx/include/log4cxx/helpers/exception.h
Index: exception.h
===================================================================
RCS file: /home/cvs/logging-log4cxx/include/log4cxx/helpers/exception.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- exception.h 24 Apr 2004 06:55:01 -0000 1.10
+++ exception.h 22 Oct 2004 15:13:36 -0000 1.11
@@ -1,19 +1,19 @@
/*
* Copyright 2003,2004 The Apache Software Foundation.
- *
+ *
* 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_HELPERS_EXCEPTION_H
#define _LOG4CXX_HELPERS_EXCEPTION_H
@@ -31,11 +31,11 @@
public:
Exception() {}
Exception(const String& message): message(message) {}
- inline const String& getMessage() { return message; }
-
+ inline const String& getMessage() const { return message; }
+
protected:
- String message;
-
+ const String message;
+
}; // class Exception
/** RuntimeException is the parent class of those exceptions that can be
@@ -60,7 +60,7 @@
: RuntimeException(message) {}
}; // class NullPointerException
- /** Thrown to indicate that a method has been passed
+ /** Thrown to indicate that a method has been passed
an illegal or inappropriate argument.*/
class LOG4CXX_EXPORT IllegalArgumentException : public RuntimeException
{
@@ -68,13 +68,15 @@
IllegalArgumentException(const String& message)
: RuntimeException(message) {}
}; // class IllegalArgumentException
-
+
/** Signals that an I/O exception of some sort has occurred. This class
is the general class of exceptions produced by failed or interrupted
I/O operations.
*/
class LOG4CXX_EXPORT IOException : public Exception
{
+ public:
+ IOException(const String& message) : Exception(message) {}
};
} // namespace helpers
}; // namespace log4cxx
1.12 +14 -5 logging-log4cxx/include/log4cxx/helpers/socketimpl.h
Index: socketimpl.h
===================================================================
RCS file: /home/cvs/logging-log4cxx/include/log4cxx/helpers/socketimpl.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- socketimpl.h 24 Apr 2004 06:55:01 -0000 1.11
+++ socketimpl.h 22 Oct 2004 15:13:36 -0000 1.12
@@ -1,19 +1,19 @@
/*
* Copyright 2003,2004 The Apache Software Foundation.
- *
+ *
* 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_HELPERS_SOCKET_IMPL
#define _LOG4CXX_HELPERS_SOCKET_IMPL
@@ -33,6 +33,9 @@
{
public:
SocketException();
+
+ private:
+ static const String createMessage();
};
/** Signals that an error occurred while attempting to connect a socket
@@ -59,12 +62,18 @@
*/
class LOG4CXX_EXPORT InterruptedIOException : public IOException
{
+ public:
+ InterruptedIOException(const String& message) :
+ IOException(message) {}
};
/** Signals that a timeout has occurred on a socket read or accept.
*/
class LOG4CXX_EXPORT SocketTimeoutException : public InterruptedIOException
{
+ public:
+ SocketTimeoutException(const String& message) :
+ InterruptedIOException(message) {}
};
class SocketImpl;
@@ -100,7 +109,7 @@
SocketImpl();
~SocketImpl();
-
+
/** @brief Accepts a connection.
@param s the connection
@throw SocketTimeoutException if a timeout was previously set with
1.16 +16 -16 logging-log4cxx/include/log4cxx/spi/loggingevent.h
Index: loggingevent.h
===================================================================
RCS file: /home/cvs/logging-log4cxx/include/log4cxx/spi/loggingevent.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- loggingevent.h 24 Apr 2004 06:55:03 -0000 1.15
+++ loggingevent.h 22 Oct 2004 15:13:36 -0000 1.16
@@ -1,19 +1,19 @@
/*
* Copyright 2003,2004 The Apache Software Foundation.
- *
+ *
* 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_SPI_LOGGING_EVENT_H
#define _LOG4CXX_SPI_LOGGING_EVENT_H
@@ -28,24 +28,24 @@
{
class Logger;
typedef helpers::ObjectPtrT<Logger> LoggerPtr;
-
+
class Level;
namespace helpers
{
class SocketOutputStream;
typedef helpers::ObjectPtrT<SocketOutputStream> SocketOutputStreamPtr;
-
+
class SocketInputStream;
typedef helpers::ObjectPtrT<SocketInputStream> SocketInputStreamPtr;
- }
-
+ }
+
namespace spi
{
class LoggingEvent;
/** smart pointer to a LoggingEvent class */
typedef helpers::ObjectPtrT<LoggingEvent> LoggingEventPtr;
-
+
/**
The internal representation of logging events. When an affirmative
decision is made to log then a <code>LoggingEvent</code> instance
@@ -54,7 +54,7 @@
<p>This class is of concern to those wishing to extend log4cxx.
*/
- class LOG4CXX_EXPORT LoggingEvent :
+ class LOG4CXX_EXPORT LoggingEvent :
public virtual helpers::ObjectImpl
{
public:
@@ -62,11 +62,11 @@
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(LoggingEvent)
END_LOG4CXX_CAST_MAP()
-
+
/** For serialization only
*/
LoggingEvent();
-
+
/**
Instantiate a LoggingEvent from the supplied parameters.
@@ -136,12 +136,12 @@
void write(helpers::SocketOutputStreamPtr& os) const;
void writeLevel(helpers::SocketOutputStreamPtr& os) const;
-
+
/** Read this event from a helpers::SocketOutputStream. */
void read(const helpers::SocketInputStreamPtr& is);
void readLevel(const helpers::SocketInputStreamPtr& is);
-
+
/**
* Returns the the context corresponding to the <code>key</code> parameter.
* If there is a local MDC copy, possibly because we are in a logging
@@ -258,7 +258,7 @@
static int64_t startTime;
};
- }
-}
+ }
+}
#endif //_LOG4CXX_SPI_LOGGING_EVENT_H
1.11 +2 -2 logging-log4cxx/src/class.cpp
Index: class.cpp
===================================================================
RCS file: /home/cvs/logging-log4cxx/src/class.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- class.cpp 21 Oct 2004 04:53:44 -0000 1.10
+++ class.cpp 22 Oct 2004 15:13:36 -0000 1.11
@@ -23,9 +23,9 @@
using namespace log4cxx::helpers;
-ClassNotFoundException::ClassNotFoundException(const String& className)
+ClassNotFoundException::ClassNotFoundException(const String& className) :
+ Exception(_T("Class '") + className + _T("' not found"))
{
- message = _T("Class '") + className + _T("' not found");
}
Class::Class(const String& name) : name(name)
1.10 +6 -6 logging-log4cxx/src/datagramsocket.cpp
Index: datagramsocket.cpp
===================================================================
RCS file: /home/cvs/logging-log4cxx/src/datagramsocket.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- datagramsocket.cpp 3 Aug 2004 06:01:25 -0000 1.9
+++ datagramsocket.cpp 22 Oct 2004 15:13:36 -0000 1.10
@@ -1,19 +1,19 @@
/*
* Copyright 2003,2004 The Apache Software Foundation.
- *
+ *
* 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.
*/
-
+
#include <log4cxx/portability.h>
#if defined(WIN32) || defined(_WIN32)
@@ -160,7 +160,7 @@
(sockaddr *)&addr, (socklen_t *)&addr_len) == -1)
#endif
{
- throw IOException();
+ throw IOException("IOException in DatagramSocket::receive");
}
}
@@ -183,7 +183,7 @@
(sockaddr *)&addr, addr_len) == -1)
#endif
{
- throw IOException();
+ throw IOException("IOException in DatagramSocket::send");
}
}
1.8 +5 -5 logging-log4cxx/src/properties.cpp
Index: properties.cpp
===================================================================
RCS file: /home/cvs/logging-log4cxx/src/properties.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- properties.cpp 22 Apr 2004 21:21:34 -0000 1.7
+++ properties.cpp 22 Oct 2004 15:13:36 -0000 1.8
@@ -1,19 +1,19 @@
/*
* Copyright 2003,2004 The Apache Software Foundation.
- *
+ *
* 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.
*/
-
+
#include <log4cxx/helpers/properties.h>
using namespace log4cxx;
@@ -292,7 +292,7 @@
if (in.bad())
{
- throw IOException();
+ throw IOException("IOException in PropertyParser::get");
}
return true;
1.16 +47 -43 logging-log4cxx/src/socketimpl.cpp
Index: socketimpl.cpp
===================================================================
RCS file: /home/cvs/logging-log4cxx/src/socketimpl.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- socketimpl.cpp 3 Aug 2004 06:01:25 -0000 1.15
+++ socketimpl.cpp 22 Oct 2004 15:13:36 -0000 1.16
@@ -1,19 +1,19 @@
/*
* Copyright 2003,2004 The Apache Software Foundation.
- *
+ *
* 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.
*/
-
+
#include <log4cxx/portability.h>
#if defined(WIN32) || defined(_WIN32)
@@ -59,43 +59,47 @@
}
#endif
-SocketException::SocketException()
-{
-#if defined(WIN32) || defined(_WIN32)
- TCHAR messageBuffer[256];
- DWORD dwError = ::WSAGetLastError();
-
- if (dwError != 0)
- {
-
- DWORD dw = ::FormatMessage(
- FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
- FORMAT_MESSAGE_MAX_WIDTH_MASK,
- NULL,
- dwError,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- messageBuffer,
- sizeof(messageBuffer)/sizeof(messageBuffer[0]),
- NULL);
-
- if (dw != 0)
- {
- message = messageBuffer;
+const String SocketException::createMessage() {
+ #if defined(WIN32) || defined(_WIN32)
+ String message;
+ TCHAR messageBuffer[256];
+ DWORD dwError = ::WSAGetLastError();
+
+ if (dwError != 0)
+ {
+
+ DWORD dw = ::FormatMessage(
+ FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
+ FORMAT_MESSAGE_MAX_WIDTH_MASK,
+ NULL,
+ dwError,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ messageBuffer,
+ sizeof(messageBuffer)/sizeof(messageBuffer[0]),
+ NULL);
+
+ if (dw != 0)
+ {
+ message = messageBuffer;
+
+ // on retire les retours chariots en fin de cha�ne
+ message = message.substr(0, message.find_last_not_of(_T("\n\r")) + 1);
+ }
+ else
+ {
+ itot(::WSAGetLastError(), messageBuffer, 10);
+ message = messageBuffer;
+ }
+ }
+ #else
+ USES_CONVERSION;
+ const TCHAR* message = A2T(strerror(errno));
+ #endif
+ return message;
+}
- // on retire les retours chariots en fin de cha�ne
- message = message.substr(0, message.find_last_not_of(_T("\n\r")) + 1);
- }
- else
- {
- itot(::WSAGetLastError(), messageBuffer, 10);
- message = messageBuffer;
- }
- }
-#else
- USES_CONVERSION;
- message = A2T(strerror(errno));
-#endif
-};
+SocketException::SocketException() : IOException(getMessage()) {
+}
SocketImpl::SocketImpl() : fd(0), localport(-1), port(0), timeout(-1)
{
@@ -138,7 +142,7 @@
int retval = ::select(this->fd+1, &rfds, NULL, NULL, &tv);
if (retval == 0)
{
- throw SocketTimeoutException();
+ throw SocketTimeoutException("Socket timeout");
}
assert(FD_ISSET(this->fd, &rfds));
@@ -172,7 +176,7 @@
{
struct sockaddr_in server_addr;
int server_len = sizeof(server_addr);
-
+
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = htonl(host.address);
server_addr.sin_port = htons(port);
@@ -199,7 +203,7 @@
{
throw SocketException();
}
-
+
address.address = 0;
fd = 0;
port = 0;
1.5 +6 -12 logging-log4cxx/tests/src/util/filter.h
Index: filter.h
===================================================================
RCS file: /home/cvs/logging-log4cxx/tests/src/util/filter.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- filter.h 24 Apr 2004 06:55:03 -0000 1.4
+++ filter.h 22 Oct 2004 15:13:36 -0000 1.5
@@ -1,12 +1,12 @@
/*
* Copyright 2003,2004 The Apache Software Foundation.
- *
+ *
* 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.
@@ -33,13 +33,7 @@
{
public:
UnexpectedFormatException(const String& message)
- : message(message) {}
-
- virtual String getMessage()
- { return message; }
-
- protected:
- String message;
+ : Exception(message) {}
};
class Filter
@@ -47,10 +41,10 @@
public:
virtual String filter(const String& in)
const throw(UnexpectedFormatException) = 0;
-
+
static String merge(const String& pattern, const String& in, const String& fmt);
static bool match(const String& pattern, const String& in);
};
-}
+}
#endif //_LOG4CXX_TESTS_UTIL_FILTER_H