One of the reasons I found that I could not use log4cpp in my recent project was that I could not control what happened if the writing to file failed. There are no exceptions and I do not appear to have any control or notification about failures.
I would therefore like to add an exception class(Log4cppException) derive it from std::exception and perhaps use it to replace ConfigureFailure - say like this
/**
* Log4cppException - overrides std::exception
*/
class Log4cppException : public std::exception {
And then in places like OstreamAppender that currently do this:
if (!_stream->good()) {
// XXX help! help!
}
say
if (!_stream->good()) {
throw Log4cppException("Failed to... ");
}
Which the 'user' of the class must catch.
I know it's a bit harder forcing clients to catch exceptions in C++, but I think it's the way to go.
Do the developers agree with this in principle, should I go ahead and submit something for your perusal?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
All warn(), info(), etc. calls are explicitly declared with 'throw()'.
The reason is that log4cpp, like log4j, is a 'best effort, fail stop' logger: log failures should not disrupt normal execution flow of a program.
So rather than throwing exceptions Appenders should call an ErrorHandler in case of failure. See the ErrorHandler and FallbackErrorHandler classes in log4j to get an idea (http://jakarta.apache.org/log4j/docs/api/org/apache/log4j/spi/ErrorHandler.html)
You're very welcome to help develop this functionality, the current policy of ignoring errors has to go.
Regards,
Bastiaan
P.S. If your interested in helping log4cpp development, please join the development mailing list, it's a more appropiate and convienient place for development related discussions.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
One of the reasons I found that I could not use log4cpp in my recent project was that I could not control what happened if the writing to file failed. There are no exceptions and I do not appear to have any control or notification about failures.
I would therefore like to add an exception class(Log4cppException) derive it from std::exception and perhaps use it to replace ConfigureFailure - say like this
/**
* Log4cppException - overrides std::exception
*/
class Log4cppException : public std::exception {
public:
Log4cppException(const std::string& msg) throw() : msg(msg) {}
virtual const char* what() const throw() {
return msg.c_str();
}
virtual ~Log4cppException() throw() {}
private:
const std::string msg;
};
And then in places like OstreamAppender that currently do this:
if (!_stream->good()) {
// XXX help! help!
}
say
if (!_stream->good()) {
throw Log4cppException("Failed to... ");
}
Which the 'user' of the class must catch.
I know it's a bit harder forcing clients to catch exceptions in C++, but I think it's the way to go.
Do the developers agree with this in principle, should I go ahead and submit something for your perusal?
Hi Peter,
All warn(), info(), etc. calls are explicitly declared with 'throw()'.
The reason is that log4cpp, like log4j, is a 'best effort, fail stop' logger: log failures should not disrupt normal execution flow of a program.
So rather than throwing exceptions Appenders should call an ErrorHandler in case of failure. See the ErrorHandler and FallbackErrorHandler classes in log4j to get an idea (http://jakarta.apache.org/log4j/docs/api/org/apache/log4j/spi/ErrorHandler.html)
You're very welcome to help develop this functionality, the current policy of ignoring errors has to go.
Regards,
Bastiaan
P.S. If your interested in helping log4cpp development, please join the development mailing list, it's a more appropiate and convienient place for development related discussions.