Changeset - c290016c8e99
[Not reviewed]
0 3 0
HanzZ - 13 years ago 2012-09-12 11:49:46
hanzz.k@gmail.com
Redirect stderr in separate method
3 files changed with 14 insertions and 6 deletions:
0 comments (0 inline, 0 general)
include/transport/logging.h
Show inline comments
 
@@ -54,10 +54,11 @@ class Config;
 

	
 
namespace Logging {
 

	
 
void initBackendLogging(Config *config);
 
void initMainLogging(Config *config);
 
void shutdownLogging();
 
void redirect_stderr();
 

	
 
}
 

	
 
}
spectrum/src/main.cpp
Show inline comments
 
@@ -312,12 +312,13 @@ int main(int argc, char **argv)
 
		// daemonize
 
		daemonize(CONFIG_STRING(&config, "service.working_dir").c_str(), CONFIG_STRING(&config, "service.pidfile").c_str());
 
// 		removeOldIcons(CONFIG_STRING(&config, "service.working_dir") + "/icons");
 
    }
 
#endif
 

	
 
	Logging::initMainLogging(&config);
 

	
 
#ifndef WIN32
 
	if (!CONFIG_STRING(&config, "service.group").empty() ||!CONFIG_STRING(&config, "service.user").empty() ) {
 
		struct rlimit limit;
 
		getrlimit(RLIMIT_CORE, &limit);
 

	
 
@@ -374,15 +375,13 @@ int main(int argc, char **argv)
 
	}
 
	else if (!storageBackend->connect()) {
 
		std::cerr << "Can't connect to database. Check the log to find out the reason.\n";
 
		return -1;
 
	}
 

	
 
	// Logging has to be initialized after all std:cerr output here, because
 
	// it forwards std::cerr to log file.
 
	Logging::initMainLogging(&config);
 
	Logging::redirect_stderr();
 

	
 
	UserManager userManager(&transport, &userRegistry, storageBackend);
 
	userManager_ = &userManager;
 

	
 
	UserRegistration *userRegistration = NULL;
 
	UsersReconnecter *usersReconnecter = NULL;
src/logging.cpp
Show inline comments
 
@@ -163,25 +163,29 @@ 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");
 

	
 
	redirect_stderr();
 
}
 

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

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

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

	
 
@@ -191,12 +195,16 @@ void initBackendLogging(Config */*config*/) {
 

	
 
void initMainLogging(Config */*config*/) {
 
}
 

	
 
void shutdownLogging() {
 
	
 
}
 

	
 
void redirect_stderr() {
 
	
 
}
 
#endif /* WITH_LOG4CXX */
 

	
 
}
 

	
 
}
0 comments (0 inline, 0 general)