Changeset - a5cf593fb7bf
[Not reviewed]
0 2 0
Jan Kaluza - 13 years ago 2012-08-20 10:59:40
hanzz.k@gmail.com
log cout and cerr using log4cxx
2 files changed with 44 insertions and 7 deletions:
0 comments (0 inline, 0 general)
spectrum/src/sample.cfg
Show inline comments
 
@@ -13,8 +13,8 @@ admin_password=test
 
#cert=server.pfx #patch to PKCS#12 certificate
 
#cert_password=test #password to that certificate if any
 
users_per_backend=10
 
backend=../..//backends/swiften/spectrum2_swiften_backend
 
#backend=../../backends/twitter/spectrum_twitter_backend
 
#backend=../..//backends/swiften/spectrum2_swiften_backend
 
backend=../../backends/twitter/spectrum2_twitter_backend
 
protocol=prpl-jabber
 
#protocol=prpl-msn
 
#protocol=any
 
@@ -43,8 +43,3 @@ prefix=twitter
 
[twitter]
 
consumer_key=qxfSCX7WN7SZl7dshqGZA
 
consumer_secret=ypWapSj87lswvnksZ46hMAoAZvST4ePGPxAQw6S2o
 
[proxy]
 
server=10.93.0.36
 
port=3128
 
user=cs09s022
 
password=proxy_password
src/logging.cpp
Show inline comments
 
@@ -52,6 +52,43 @@ namespace Logging {
 
using namespace log4cxx;
 
static LoggerPtr root;
 

	
 

	
 
class intercept_stream : public std::streambuf{
 
public:
 
    intercept_stream(std::ostream& stream, char const* logger):
 
      _logger(log4cxx::Logger::getLogger(logger))
 
    {
 
		stream.rdbuf(this);
 
    }
 
    ~intercept_stream(){
 
    }
 
protected:
 
    virtual std::streamsize xsputn(const char *msg, std::streamsize count){
 

	
 
        //Output to log4cxx logger
 
        std::string s(msg,count);
 
		LOG4CXX_INFO(_logger, msg);
 
        return count;
 
    }
 

	
 
	int overflow(int c)
 
	{
 
		return 0;
 
	}
 

	
 
	int sync()
 
	{
 
		return 0;
 
	}
 

	
 
private:
 
    log4cxx::LoggerPtr _logger;
 
};
 

	
 
static intercept_stream* intercepter_cout;
 
static intercept_stream* intercepter_cerr;
 

	
 

	
 
static void initLogging(Config *config, std::string key) {
 
	if (CONFIG_STRING(config, key).empty()) {
 
		root = log4cxx::Logger::getRootLogger();
 
@@ -129,6 +166,9 @@ static void initLogging(Config *config, std::string key) {
 

	
 
		log4cxx::PropertyConfigurator::configure(p);
 
	}
 

	
 
	 intercepter_cerr = new intercept_stream(std::cerr, "cerr");
 
	 intercepter_cout = new intercept_stream(std::cout, "cout");
 
}
 

	
 
void initBackendLogging(Config *config) {
 
@@ -140,6 +180,8 @@ void initMainLogging(Config *config) {
 
}
 

	
 
void shutdownLogging() {
 
	delete intercepter_cerr;
 
	delete intercepter_cout;
 
	log4cxx::LogManager::shutdown();
 
}
 

	
0 comments (0 inline, 0 general)