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
 
@@ -10,14 +10,14 @@ pidfile=./test.pid
 
#backend_port=10001
 
#admin_jid=admin@localhost
 
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
 
#protocol=prpl-icq
 
working_dir=./
 
portfile=$jid.port
 
@@ -40,11 +40,6 @@ prefix=twitter
 
#user=root
 
#password=yourrootsqlpassword
 
#encryption_key=hanzzik
 
[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
 
@@ -49,12 +49,49 @@ namespace Transport {
 
namespace Logging {
 

	
 
#ifdef WITH_LOG4CXX
 
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();
 
#ifdef WIN32
 
		root->addAppender(new ConsoleAppender(new PatternLayout(L"%d %-5p %c: %m%n")));
 
#else
 
@@ -126,23 +163,28 @@ static void initLogging(Config *config, std::string key) {
 

	
 
#endif
 
		}
 

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

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

	
 
void initBackendLogging(Config *config) {
 
	initLogging(config, "logging.backend_config");
 
}
 

	
 
void initMainLogging(Config *config) {
 
	initLogging(config, "logging.config");
 
}
 

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

	
 
#else /* WITH_LOG4CXX */
 
void initBackendLogging(Config */*config*/) {
 
}
0 comments (0 inline, 0 general)