From 1f60d0547cc5cb96ac6dc797193b2a0dc6be96d3 Mon Sep 17 00:00:00 2001 From: HanzZ Date: Wed, 21 Mar 2012 15:46:25 +0100 Subject: [PATCH 1/3] Changed libtransport-plugin deps to have logging.h used from libpurple backend --- backends/libpurple/main.cpp | 44 ++++++------------------------------- plugin/cpp/CMakeLists.txt | 6 +++-- src/config.cpp | 13 ++++++++--- 3 files changed, 21 insertions(+), 42 deletions(-) diff --git a/backends/libpurple/main.cpp b/backends/libpurple/main.cpp index 8c9c7b48..a39f5218 100644 --- a/backends/libpurple/main.cpp +++ b/backends/libpurple/main.cpp @@ -6,6 +6,8 @@ #include #include "transport/networkplugin.h" +#include "transport/logging.h" +#include "transport/config.h" #include "geventloop.h" #include "log4cxx/logger.h" #include "log4cxx/consoleappender.h" @@ -1648,44 +1650,12 @@ int main(int argc, char **argv) { return 1; } - if (KEYFILE_STRING("logging", "backend_config").empty()) { - LoggerPtr root = log4cxx::Logger::getRootLogger(); -#ifndef _MSC_VER - root->addAppender(new ConsoleAppender(new PatternLayout("%d %-5p %c: %m%n"))); -#else - root->addAppender(new ConsoleAppender(new PatternLayout(L"%d %-5p %c: %m%n"))); -#endif - } - else { - log4cxx::helpers::Properties p; - log4cxx::helpers::FileInputStream *istream = NULL; - try { - istream = new log4cxx::helpers::FileInputStream(KEYFILE_STRING("logging", "backend_config")); - } - catch(log4cxx::helpers::IOException &ex) { - std::cerr << "Can't create FileInputStream logger instance: " << ex.what() << "\n"; - } - catch (...) { - std::cerr << "Can't create FileInputStream logger instance\n"; - } - - if (!istream) { - return 1; - } - - p.load(istream); - LogString pid, jid; - log4cxx::helpers::Transcoder::decode(stringOf(getpid()), pid); - log4cxx::helpers::Transcoder::decode(KEYFILE_STRING("service", "jid"), jid); -#ifdef _MSC_VER - p.setProperty(L"pid", pid); - p.setProperty(L"jid", jid); -#else - p.setProperty("pid", pid); - p.setProperty("jid", jid); -#endif - log4cxx::PropertyConfigurator::configure(p); + Config config; + if (!config.load(argv[1])) { + std::cerr << "Can't open " << argv[1] << " configuration file.\n"; + return 1; } + Logging::initBackendLogging(&config); initPurple(); diff --git a/plugin/cpp/CMakeLists.txt b/plugin/cpp/CMakeLists.txt index 544e2ec2..b41b3453 100644 --- a/plugin/cpp/CMakeLists.txt +++ b/plugin/cpp/CMakeLists.txt @@ -3,6 +3,8 @@ FILE(GLOB SRC *.cpp *.h) FILE(GLOB HEADERS ../include/transport/*.h) set(EXTRA_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/../../src/memoryusage.cpp) +set(EXTRA_SOURCES ${EXTRA_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/../../src/logging.cpp) +set(EXTRA_SOURCES ${EXTRA_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/../../src/config.cpp) set(EXTRA_SOURCES ${EXTRA_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/../../include/transport/protocol.pb.cc) if (NOT WIN32) @@ -18,9 +20,9 @@ if (CMAKE_COMPILER_IS_GNUCXX) endif() if (NOT WIN32) - TARGET_LINK_LIBRARIES(transport-plugin ${PROTOBUF_LIBRARIES} ${LOG4CXX_LIBRARIES}) + TARGET_LINK_LIBRARIES(transport-plugin ${PROTOBUF_LIBRARIES} ${LOG4CXX_LIBRARIES} ${Boost_LIBRARIES}) else() - TARGET_LINK_LIBRARIES(transport-plugin ${PROTOBUF_LIBRARIES} ${LOG4CXX_LIBRARIES} ws2_32.lib) + TARGET_LINK_LIBRARIES(transport-plugin ${PROTOBUF_LIBRARIES} ${LOG4CXX_LIBRARIES} ${Boost_LIBRARIES} ws2_32.lib) endif() SET_TARGET_PROPERTIES(transport-plugin PROPERTIES diff --git a/src/config.cpp b/src/config.cpp index 7088889c..5962cc25 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -19,7 +19,6 @@ */ #include "transport/config.h" -#include "transport/util.h" #include #ifdef _MSC_VER #include @@ -31,6 +30,14 @@ using namespace boost::program_options; namespace Transport { +int getRandomPort(const std::string &s) { + unsigned long r = 0; + BOOST_FOREACH(char c, s) { + r += (int) c; + } + srand(time(NULL) + r); + return 30000 + rand() % 10000; +} bool Config::load(const std::string &configfile, boost::program_options::options_description &opts, const std::string &jid) { std::ifstream ifs(configfile.c_str()); @@ -126,7 +133,7 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description else if (opt.string_key == "service.backend_port") { found_backend_port = true; if (opt.value[0] == "0") { - opt.value[0] = boost::lexical_cast(Util::getRandomPort(_jid.empty() ? jid : _jid)); + opt.value[0] = boost::lexical_cast(getRandomPort(_jid.empty() ? jid : _jid)); } } else if (opt.string_key == "service.working_dir") { @@ -152,7 +159,7 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description } if (!found_backend_port) { std::vector value; - std::string p = boost::lexical_cast(Util::getRandomPort(_jid.empty() ? jid : _jid)); + std::string p = boost::lexical_cast(getRandomPort(_jid.empty() ? jid : _jid)); value.push_back(p); parsed.options.push_back(boost::program_options::basic_option("service.backend_port", value)); } From 7c93aee6f49a37fd1956a42afebf93935b116ffa Mon Sep 17 00:00:00 2001 From: HanzZ Date: Wed, 21 Mar 2012 16:31:51 +0100 Subject: [PATCH 2/3] Log4cxx is optional dependency now --- CMakeLists.txt | 6 ++- backends/libcommuni/main.cpp | 10 ----- backends/libcommuni/session.cpp | 6 +-- .../libcommuni/singleircnetworkplugin.cpp | 6 +-- backends/libpurple/geventloop.cpp | 6 +-- backends/libpurple/main.cpp | 13 ++----- backends/skype/main.cpp | 11 +----- backends/smstools3/main.cpp | 11 +----- backends/template/main.cpp | 39 ++----------------- .../TLS/OpenSSL/OpenSSLServerContext.cpp | 8 +--- include/transport/logging.h | 22 +++++++++++ plugin/cpp/networkplugin.cpp | 9 ++--- spectrum/src/main.cpp | 11 +----- src/admininterface.cpp | 6 +-- src/blockresponder.cpp | 6 +-- src/conversation.cpp | 5 --- src/conversationmanager.cpp | 6 +-- src/filetransfermanager.cpp | 6 +-- src/gatewayresponder.cpp | 6 +-- src/logging.cpp | 20 ++++++---- src/memoryreadbytestream.cpp | 3 -- src/mysqlbackend.cpp | 6 +-- src/networkpluginserver.cpp | 6 +-- src/rostermanager.cpp | 6 +-- src/rosterresponder.cpp | 6 +-- src/sqlite3backend.cpp | 6 +-- src/statsresponder.cpp | 6 +-- src/storageresponder.cpp | 6 +-- src/tests/main.cpp | 4 ++ src/transport.cpp | 10 ++--- src/user.cpp | 5 +-- src/usermanager.cpp | 7 ++-- src/userregistration.cpp | 5 +-- src/userregistry.cpp | 6 +-- src/usersreconnecter.cpp | 6 +-- src/vcardresponder.cpp | 6 +-- 36 files changed, 104 insertions(+), 203 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c1ef558..78c29c74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -167,10 +167,12 @@ else() endif() if (LOG4CXX_FOUND) - message("Logging : yes") + message("Log4cxx : yes") include_directories(${LOG4CXX_INCLUDE_DIR}) + ADD_DEFINITIONS(-DWITH_LOG4CXX) else() - message(FATAL_ERROR "Logging : no (install log4cxx-devel)") + set(LOG4CXX_LIBRARIES "") + message("Log4cxx : no (install log4cxx-devel)") endif() if (WIN32) diff --git a/backends/libcommuni/main.cpp b/backends/libcommuni/main.cpp index 6443c2bd..9b717d4c 100644 --- a/backends/libcommuni/main.cpp +++ b/backends/libcommuni/main.cpp @@ -18,19 +18,9 @@ #include "ircnetworkplugin.h" #include "singleircnetworkplugin.h" -#include "log4cxx/logger.h" -#include "log4cxx/consoleappender.h" -#include "log4cxx/patternlayout.h" -#include "log4cxx/propertyconfigurator.h" -#include "log4cxx/helpers/properties.h" -#include "log4cxx/helpers/fileinputstream.h" -#include "log4cxx/helpers/transcoder.h" - using namespace boost::program_options; using namespace Transport; -using namespace log4cxx; - NetworkPlugin * np = NULL; int main (int argc, char* argv[]) { diff --git a/backends/libcommuni/session.cpp b/backends/libcommuni/session.cpp index 971c2c0c..ac972b5f 100644 --- a/backends/libcommuni/session.cpp +++ b/backends/libcommuni/session.cpp @@ -15,11 +15,9 @@ #include #include -#include "log4cxx/logger.h" +#include "transport/logging.h" -using namespace log4cxx; - -static LoggerPtr logger = log4cxx::Logger::getLogger("IRCSession"); +DEFINE_LOGGER(logger, "IRCSession"); MyIrcSession::MyIrcSession(const std::string &user, NetworkPlugin *np, const std::string &suffix, QObject* parent) : IrcSession(parent) { diff --git a/backends/libcommuni/singleircnetworkplugin.cpp b/backends/libcommuni/singleircnetworkplugin.cpp index 06bd378c..f668e543 100644 --- a/backends/libcommuni/singleircnetworkplugin.cpp +++ b/backends/libcommuni/singleircnetworkplugin.cpp @@ -1,11 +1,9 @@ #include "singleircnetworkplugin.h" -#include "log4cxx/logger.h" +#include "transport/logging.h" #include #include -using namespace log4cxx; - -static LoggerPtr logger = log4cxx::Logger::getLogger("SingleIRCNetworkPlugin"); +DEFINE_LOGGER(logger, "SingleIRCNetworkPlugin"); SingleIRCNetworkPlugin::SingleIRCNetworkPlugin(Config *config, Swift::QtEventLoop *loop, const std::string &host, int port) { this->config = config; diff --git a/backends/libpurple/geventloop.cpp b/backends/libpurple/geventloop.cpp index b32c893d..1dacea40 100644 --- a/backends/libpurple/geventloop.cpp +++ b/backends/libpurple/geventloop.cpp @@ -28,11 +28,9 @@ #include "event.h" #endif -#include "log4cxx/logger.h" +#include "transport/logging.h" -using namespace log4cxx; - -static LoggerPtr logger = Logger::getLogger("EventLoop"); +DEFINE_LOGGER(logger, "EventLoop"); typedef struct _PurpleIOClosure { PurpleInputFunction function; diff --git a/backends/libpurple/main.cpp b/backends/libpurple/main.cpp index a39f5218..c971f273 100644 --- a/backends/libpurple/main.cpp +++ b/backends/libpurple/main.cpp @@ -8,14 +8,8 @@ #include "transport/networkplugin.h" #include "transport/logging.h" #include "transport/config.h" +#include "transport/logging.h" #include "geventloop.h" -#include "log4cxx/logger.h" -#include "log4cxx/consoleappender.h" -#include "log4cxx/patternlayout.h" -#include "log4cxx/propertyconfigurator.h" -#include "log4cxx/helpers/properties.h" -#include "log4cxx/helpers/fileinputstream.h" -#include "log4cxx/helpers/transcoder.h" // #include "valgrind/memcheck.h" #include "malloc.h" @@ -33,10 +27,9 @@ #define getpid _getpid #endif -using namespace log4cxx; +DEFINE_LOGGER(logger_libpurple, "libpurple"); +DEFINE_LOGGER(logger, "backend"); -static LoggerPtr logger_libpurple = log4cxx::Logger::getLogger("libpurple"); -static LoggerPtr logger = log4cxx::Logger::getLogger("backend"); int main_socket; static int writeInput; diff --git a/backends/skype/main.cpp b/backends/skype/main.cpp index c98b1498..7a081114 100644 --- a/backends/skype/main.cpp +++ b/backends/skype/main.cpp @@ -14,13 +14,8 @@ #include "transport/rostermanager.h" #include "transport/conversation.h" #include "transport/networkplugin.h" +#include "transport/logger.h" #include -#include "log4cxx/logger.h" -#include "log4cxx/consoleappender.h" -#include "log4cxx/patternlayout.h" -#include "log4cxx/propertyconfigurator.h" -#include "log4cxx/helpers/properties.h" -#include "log4cxx/helpers/fileinputstream.h" #include "sys/wait.h" #include "sys/signal.h" // #include "valgrind/memcheck.h" @@ -28,9 +23,7 @@ #include -using namespace log4cxx; - -static LoggerPtr logger = Logger::getLogger("backend"); +DEFINE_LOGGER(logger, "backend"); using namespace Transport; diff --git a/backends/smstools3/main.cpp b/backends/smstools3/main.cpp index a6502bdc..2e61868c 100644 --- a/backends/smstools3/main.cpp +++ b/backends/smstools3/main.cpp @@ -26,13 +26,6 @@ Swift::SimpleEventLoop *loop_; -#include "log4cxx/logger.h" -#include "log4cxx/consoleappender.h" -#include "log4cxx/patternlayout.h" -#include "log4cxx/propertyconfigurator.h" -#include "log4cxx/helpers/properties.h" -#include "log4cxx/helpers/fileinputstream.h" -#include "log4cxx/helpers/transcoder.h" #include #include @@ -41,9 +34,7 @@ using namespace boost::filesystem; using namespace boost::program_options; using namespace Transport; -using namespace log4cxx; - -static LoggerPtr logger = log4cxx::Logger::getLogger("SMSNetworkPlugin"); +DEFINE_LOGGER(logger, "SMSNetworkPlugin"); #define INTERNAL_USER "/sms@backend@internal@user" diff --git a/backends/template/main.cpp b/backends/template/main.cpp index 44fc8623..595ce42d 100644 --- a/backends/template/main.cpp +++ b/backends/template/main.cpp @@ -1,6 +1,7 @@ // Transport includes #include "transport/config.h" #include "transport/networkplugin.h" +#include "transport/logging.h" // Swiften #include "Swiften/Swiften.h" @@ -11,24 +12,13 @@ #include "sys/wait.h" #include "sys/signal.h" -// Log4cxx -#include "log4cxx/logger.h" -#include "log4cxx/consoleappender.h" -#include "log4cxx/patternlayout.h" -#include "log4cxx/propertyconfigurator.h" -#include "log4cxx/helpers/properties.h" -#include "log4cxx/helpers/fileinputstream.h" -#include "log4cxx/helpers/transcoder.h" - // Boost #include using namespace boost::filesystem; using namespace boost::program_options; using namespace Transport; -// log4cxx main logger -using namespace log4cxx; -static LoggerPtr logger = log4cxx::Logger::getLogger("Backend Template"); +DEFINE_LOGGER(logger, "Backend Template"); // eventloop Swift::SimpleEventLoop *loop_; @@ -147,30 +137,7 @@ int main (int argc, char* argv[]) { return 1; } - if (CONFIG_STRING(&config, "logging.backend_config").empty()) { - LoggerPtr root = log4cxx::Logger::getRootLogger(); -#ifndef _MSC_VER - root->addAppender(new ConsoleAppender(new PatternLayout("%d %-5p %c: %m%n"))); -#else - root->addAppender(new ConsoleAppender(new PatternLayout(L"%d %-5p %c: %m%n"))); -#endif - } - else { - log4cxx::helpers::Properties p; - log4cxx::helpers::FileInputStream *istream = new log4cxx::helpers::FileInputStream(CONFIG_STRING(&config, "logging.backend_config")); - p.load(istream); - LogString pid, jid; - log4cxx::helpers::Transcoder::decode(boost::lexical_cast(getpid()), pid); - log4cxx::helpers::Transcoder::decode(CONFIG_STRING(&config, "service.jid"), jid); -#ifdef _MSC_VER - p.setProperty(L"pid", pid); - p.setProperty(L"jid", jid); -#else - p.setProperty("pid", pid); - p.setProperty("jid", jid); -#endif - log4cxx::PropertyConfigurator::configure(p); - } + Logging::initBackendLogging(&config); Swift::SimpleEventLoop eventLoop; loop_ = &eventLoop; diff --git a/include/Swiften/TLS/OpenSSL/OpenSSLServerContext.cpp b/include/Swiften/TLS/OpenSSL/OpenSSLServerContext.cpp index ebf798be..40218daa 100644 --- a/include/Swiften/TLS/OpenSSL/OpenSSLServerContext.cpp +++ b/include/Swiften/TLS/OpenSSL/OpenSSLServerContext.cpp @@ -14,12 +14,8 @@ #include #include -#include "log4cxx/logger.h" -#include "log4cxx/consoleappender.h" -#include "log4cxx/patternlayout.h" -#include "log4cxx/propertyconfigurator.h" -using namespace log4cxx; -static LoggerPtr logger = Logger::getLogger("OpenSSLServerContext"); +#include "transport/logging.h" +DEFINE_LOGGER(logger, "OpenSSLServerContext"); #include "Swiften/TLS/OpenSSL/OpenSSLServerContext.h" diff --git a/include/transport/logging.h b/include/transport/logging.h index 79b1dfd5..4abf92dd 100644 --- a/include/transport/logging.h +++ b/include/transport/logging.h @@ -24,6 +24,28 @@ #include #include #include +#include + +#ifdef WITH_LOG4CXX +#include "log4cxx/logger.h" +#include "log4cxx/consoleappender.h" +#include "log4cxx/patternlayout.h" +#include "log4cxx/propertyconfigurator.h" +#include "log4cxx/helpers/properties.h" +#include "log4cxx/helpers/fileinputstream.h" +#include "log4cxx/helpers/transcoder.h" +#include "log4cxx/logger.h" + +#define DEFINE_LOGGER(VAR, NAME) static log4cxx::LoggerPtr VAR = log4cxx::Logger::getLogger(NAME); + +using namespace log4cxx; +#else +#define DEFINE_LOGGER(VARIABLE, NAME) static const char *VARIABLE = NAME; + +#define LOG4CXX_ERROR(LOGGER, DATA) std::cerr << "E: <" << LOGGER << "> " << DATA << "\n"; +#define LOG4CXX_WARN(LOGGER, DATA) std::cout << "W: <" << LOGGER << "> " << DATA << "\n"; +#define LOG4CXX_INFO(LOGGER, DATA) std::cout << "I: <" << LOGGER << "> " << DATA << "\n"; +#endif namespace Transport { diff --git a/plugin/cpp/networkplugin.cpp b/plugin/cpp/networkplugin.cpp index 1b7f448c..179b2f08 100644 --- a/plugin/cpp/networkplugin.cpp +++ b/plugin/cpp/networkplugin.cpp @@ -19,9 +19,10 @@ */ #include "transport/networkplugin.h" -#include "log4cxx/logger.h" -#include "log4cxx/basicconfigurator.h" #include "transport/memoryusage.h" +#include "transport/logging.h" + +#include #ifndef WIN32 #include @@ -32,9 +33,7 @@ #define getpid _getpid #endif -using namespace log4cxx; - -static LoggerPtr logger = Logger::getLogger("NetworkPlugin"); +DEFINE_LOGGER(logger, "NetworkPlugin"); namespace Transport { diff --git a/spectrum/src/main.cpp b/spectrum/src/main.cpp index be525f60..82540d11 100644 --- a/spectrum/src/main.cpp +++ b/spectrum/src/main.cpp @@ -26,20 +26,11 @@ #else #include #endif -#include "log4cxx/logger.h" -#include "log4cxx/consoleappender.h" -#include "log4cxx/patternlayout.h" -#include "log4cxx/propertyconfigurator.h" -#include "log4cxx/helpers/properties.h" -#include "log4cxx/helpers/transcoder.h" -#include "log4cxx/helpers/fileinputstream.h" #include -using namespace log4cxx; - using namespace Transport; -static LoggerPtr logger = log4cxx::Logger::getLogger("Spectrum"); +DEFINE_LOGGER(logger, "Spectrum"); Swift::SimpleEventLoop *eventLoop_ = NULL; Component *component_ = NULL; diff --git a/src/admininterface.cpp b/src/admininterface.cpp index cec4dfa6..c79db37c 100644 --- a/src/admininterface.cpp +++ b/src/admininterface.cpp @@ -26,16 +26,14 @@ #include "transport/rostermanager.h" #include "transport/usermanager.h" #include "transport/networkpluginserver.h" +#include "transport/logging.h" #include "storageresponder.h" -#include "log4cxx/logger.h" #include "transport/memoryusage.h" #include -using namespace log4cxx; - namespace Transport { -static LoggerPtr logger = Logger::getLogger("AdminInterface"); +DEFINE_LOGGER(logger, "AdminInterface"); static std::string getArg(const std::string &body) { std::string ret; diff --git a/src/blockresponder.cpp b/src/blockresponder.cpp index 9737907a..708fec43 100644 --- a/src/blockresponder.cpp +++ b/src/blockresponder.cpp @@ -29,16 +29,14 @@ #include "transport/user.h" #include "transport/buddy.h" #include "transport/rostermanager.h" -#include "log4cxx/logger.h" - -using namespace log4cxx; +#include "transport/logging.h" using namespace Swift; using namespace boost; namespace Transport { -static LoggerPtr logger = Logger::getLogger("BlockResponder"); +DEFINE_LOGGER(logger, "BlockResponder"); BlockResponder::BlockResponder(Swift::IQRouter *router, UserManager *userManager) : Swift::SetResponder(router) { m_userManager = userManager; diff --git a/src/conversation.cpp b/src/conversation.cpp index d903e320..571a4cde 100644 --- a/src/conversation.cpp +++ b/src/conversation.cpp @@ -25,14 +25,9 @@ #include "transport/transport.h" #include "transport/buddy.h" #include "transport/rostermanager.h" -#include "log4cxx/logger.h" - -using namespace log4cxx; namespace Transport { -// static LoggerPtr logger = Logger::getLogger("Conversation"); - Conversation::Conversation(ConversationManager *conversationManager, const std::string &legacyName, bool isMUC) : m_conversationManager(conversationManager) { m_legacyName = legacyName; m_conversationManager->addConversation(this); diff --git a/src/conversationmanager.cpp b/src/conversationmanager.cpp index bc08d7a7..6a5d7d16 100644 --- a/src/conversationmanager.cpp +++ b/src/conversationmanager.cpp @@ -24,16 +24,14 @@ #include "transport/buddy.h" #include "transport/factory.h" #include "transport/user.h" +#include "transport/logging.h" #include "Swiften/Roster/SetRosterRequest.h" #include "Swiften/Elements/RosterPayload.h" #include "Swiften/Elements/RosterItemPayload.h" -#include "log4cxx/logger.h" - -using namespace log4cxx; namespace Transport { -static LoggerPtr logger = Logger::getLogger("ConversationManager"); +DEFINE_LOGGER(logger, "ConversationManager"); ConversationManager::ConversationManager(User *user, Component *component){ m_user = user; diff --git a/src/filetransfermanager.cpp b/src/filetransfermanager.cpp index 8fcacdcf..73c08a86 100644 --- a/src/filetransfermanager.cpp +++ b/src/filetransfermanager.cpp @@ -23,13 +23,11 @@ #include "transport/usermanager.h" #include "transport/user.h" #include "transport/buddy.h" -#include "log4cxx/logger.h" - -using namespace log4cxx; +#include "transport/logging.h" namespace Transport { -static LoggerPtr logger = Logger::getLogger("FileTransferManager"); +DEFINE_LOGGER(logger, "FileTransferManager"); FileTransferManager::FileTransferManager(Component *component, UserManager *userManager) { m_component = component; diff --git a/src/gatewayresponder.cpp b/src/gatewayresponder.cpp index 903c069a..2f7c0c35 100644 --- a/src/gatewayresponder.cpp +++ b/src/gatewayresponder.cpp @@ -28,16 +28,14 @@ #include "transport/usermanager.h" #include "transport/user.h" #include "transport/transport.h" -#include "log4cxx/logger.h" - -using namespace log4cxx; +#include "transport/logging.h" using namespace Swift; using namespace boost; namespace Transport { -static LoggerPtr logger = Logger::getLogger("GatewayResponder"); +DEFINE_LOGGER(logger, "GatewayResponder"); GatewayResponder::GatewayResponder(Swift::IQRouter *router, UserManager *userManager) : Swift::Responder(router) { m_userManager = userManager; diff --git a/src/logging.cpp b/src/logging.cpp index fc9f94b3..3d56878f 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -25,13 +25,7 @@ #include #include -#include "log4cxx/logger.h" -#include "log4cxx/consoleappender.h" -#include "log4cxx/patternlayout.h" -#include "log4cxx/propertyconfigurator.h" -#include "log4cxx/helpers/properties.h" -#include "log4cxx/helpers/fileinputstream.h" -#include "log4cxx/helpers/transcoder.h" + #include #include @@ -48,12 +42,14 @@ #endif using namespace boost::filesystem; -using namespace log4cxx; + namespace Transport { namespace Logging { +#ifdef WITH_LOG4CXX +using namespace log4cxx; static LoggerPtr root; static void initLogging(Config *config, std::string key) { @@ -143,6 +139,14 @@ void initMainLogging(Config *config) { initLogging(config, "logging.config"); } +#else /* WITH_LOG4CXX */ +void initBackendLogging(Config */*config*/) { +} + +void initMainLogging(Config */*config*/) { +} +#endif /* WITH_LOG4CXX */ + } } diff --git a/src/memoryreadbytestream.cpp b/src/memoryreadbytestream.cpp index 1c74ec3e..83514ada 100644 --- a/src/memoryreadbytestream.cpp +++ b/src/memoryreadbytestream.cpp @@ -19,11 +19,8 @@ */ #include "transport/memoryreadbytestream.h" -#include "log4cxx/logger.h" #include -using namespace log4cxx; - namespace Transport { MemoryReadBytestream::MemoryReadBytestream(unsigned long size) { diff --git a/src/mysqlbackend.cpp b/src/mysqlbackend.cpp index 1af53c3a..9bb5eaef 100644 --- a/src/mysqlbackend.cpp +++ b/src/mysqlbackend.cpp @@ -22,10 +22,8 @@ #include "transport/mysqlbackend.h" #include "transport/util.h" +#include "transport/logging.h" #include -#include "log4cxx/logger.h" - -using namespace log4cxx; #define MYSQL_DB_VERSION 2 #define CHECK_DB_RESPONSE(stmt) \ @@ -92,7 +90,7 @@ using namespace boost; namespace Transport { -static LoggerPtr logger = Logger::getLogger("MySQLBackend"); +DEFINE_LOGGER(logger, "MySQLBackend"); static bool exec_ok; MySQLBackend::Statement::Statement(MYSQL *conn, const std::string &format, const std::string &statement) { diff --git a/src/networkpluginserver.cpp b/src/networkpluginserver.cpp index 00f601d7..90d66759 100644 --- a/src/networkpluginserver.cpp +++ b/src/networkpluginserver.cpp @@ -31,6 +31,7 @@ #include "transport/vcardresponder.h" #include "transport/rosterresponder.h" #include "transport/memoryreadbytestream.h" +#include "transport/logging.h" #include "blockresponder.h" #include "Swiften/Swiften.h" #include "Swiften/Server/ServerStanzaChannel.h" @@ -41,7 +42,6 @@ #include "Swiften/Elements/InvisiblePayload.h" #include "Swiften/Elements/SpectrumErrorPayload.h" #include "transport/protocol.pb.h" -#include "log4cxx/logger.h" #include #include @@ -55,14 +55,12 @@ #include "popt.h" #endif -using namespace log4cxx; - namespace Transport { static unsigned long backend_id; static unsigned long bytestream_id; -static LoggerPtr logger = Logger::getLogger("NetworkPluginServer"); +DEFINE_LOGGER(logger, "NetworkPluginServer"); class NetworkConversation : public Conversation { public: diff --git a/src/rostermanager.cpp b/src/rostermanager.cpp index 1bde0173..ea49430b 100644 --- a/src/rostermanager.cpp +++ b/src/rostermanager.cpp @@ -25,21 +25,19 @@ #include "transport/usermanager.h" #include "transport/buddy.h" #include "transport/user.h" +#include "transport/logging.h" #include "Swiften/Roster/SetRosterRequest.h" #include "Swiften/Elements/RosterPayload.h" #include "Swiften/Elements/RosterItemPayload.h" #include "Swiften/Elements/RosterItemExchangePayload.h" -#include "log4cxx/logger.h" #include #include #include -using namespace log4cxx; - namespace Transport { -static LoggerPtr logger = Logger::getLogger("RosterManager"); +DEFINE_LOGGER(logger, "RosterManager"); RosterManager::RosterManager(User *user, Component *component){ m_rosterStorage = NULL; diff --git a/src/rosterresponder.cpp b/src/rosterresponder.cpp index fe243bcc..3b0c4612 100644 --- a/src/rosterresponder.cpp +++ b/src/rosterresponder.cpp @@ -28,16 +28,14 @@ #include "transport/usermanager.h" #include "transport/rostermanager.h" #include "transport/buddy.h" -#include "log4cxx/logger.h" - -using namespace log4cxx; +#include "transport/logging.h" using namespace Swift; using namespace boost; namespace Transport { -static LoggerPtr logger = Logger::getLogger("RosterResponder"); +DEFINE_LOGGER(logger, "RosterResponder"); RosterResponder::RosterResponder(Swift::IQRouter *router, UserManager *userManager) : Swift::Responder(router) { m_userManager = userManager; diff --git a/src/sqlite3backend.cpp b/src/sqlite3backend.cpp index c61ca628..e9a11dac 100644 --- a/src/sqlite3backend.cpp +++ b/src/sqlite3backend.cpp @@ -22,10 +22,8 @@ #include "transport/sqlite3backend.h" #include "transport/util.h" +#include "transport/logging.h" #include -#include "log4cxx/logger.h" - -using namespace log4cxx; #define SQLITE_DB_VERSION 3 #define CHECK_DB_RESPONSE(stmt) \ @@ -65,7 +63,7 @@ using namespace boost; namespace Transport { -static LoggerPtr logger = Logger::getLogger("SQLite3Backend"); +DEFINE_LOGGER(logger, "SQLite3Backend"); SQLite3Backend::SQLite3Backend(Config *config) { m_config = config; diff --git a/src/statsresponder.cpp b/src/statsresponder.cpp index bf4e4b5f..4ba24e71 100644 --- a/src/statsresponder.cpp +++ b/src/statsresponder.cpp @@ -34,16 +34,14 @@ #include "transport/rostermanager.h" #include "transport/usermanager.h" #include "transport/networkpluginserver.h" -#include "log4cxx/logger.h" - -using namespace log4cxx; +#include "transport/logging.h" using namespace Swift; using namespace boost; namespace Transport { -static LoggerPtr logger = Logger::getLogger("StatsResponder"); +DEFINE_LOGGER(logger, "StatsResponder"); StatsResponder::StatsResponder(Component *component, UserManager *userManager, NetworkPluginServer *server, StorageBackend *storageBackend) : Swift::Responder(component->getIQRouter()) { m_component = component; diff --git a/src/storageresponder.cpp b/src/storageresponder.cpp index b5f4e5aa..1b3d2aa9 100644 --- a/src/storageresponder.cpp +++ b/src/storageresponder.cpp @@ -27,16 +27,14 @@ #include "Swiften/Swiften.h" #include "transport/usermanager.h" #include "transport/user.h" -#include "log4cxx/logger.h" - -using namespace log4cxx; +#include "transport/logging.h" using namespace Swift; using namespace boost; namespace Transport { -static LoggerPtr logger = Logger::getLogger("StorageResponder"); +DEFINE_LOGGER(logger, "StorageResponder"); StorageResponder::StorageResponder(Swift::IQRouter *router, StorageBackend *storageBackend, UserManager *userManager) : Swift::Responder(router) { m_storageBackend = storageBackend; diff --git a/src/tests/main.cpp b/src/tests/main.cpp index 55ba41ae..aea740f0 100644 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -5,18 +5,22 @@ #include #include #include +#ifdef WITH_LOG4CXX #include "log4cxx/logger.h" #include "log4cxx/fileappender.h" #include "log4cxx/patternlayout.h" #include "log4cxx/propertyconfigurator.h" using namespace log4cxx; +#endif int main (int argc, char* argv[]) { +#ifdef WITH_LOG4CXX LoggerPtr root = Logger::getRootLogger(); root->addAppender(new FileAppender(new PatternLayout("%d %-5p %c: %m%n"), "libtransport_test.log", false)); +#endif // informs test-listener about testresults CPPUNIT_NS :: TestResult testresult; diff --git a/src/transport.cpp b/src/transport.cpp index 8eab7bf7..581670af 100644 --- a/src/transport.cpp +++ b/src/transport.cpp @@ -24,6 +24,7 @@ #include "transport/storagebackend.h" #include "transport/factory.h" #include "transport/userregistry.h" +#include "transport/logging.h" #include "discoinforesponder.h" #include "discoitemsresponder.h" #include "storageparser.h" @@ -43,20 +44,15 @@ #include "transport/BlockSerializer.h" #include "Swiften/Parser/PayloadParsers/InvisibleParser.h" #include "Swiften/Serializer/PayloadSerializers/InvisibleSerializer.h" -#include "log4cxx/logger.h" -#include "log4cxx/consoleappender.h" -#include "log4cxx/patternlayout.h" -#include "log4cxx/propertyconfigurator.h" #include "Swiften/Swiften.h" using namespace Swift; using namespace boost; -using namespace log4cxx; namespace Transport { -static LoggerPtr logger = Logger::getLogger("Component"); -static LoggerPtr logger_xml = Logger::getLogger("Component.XML"); +DEFINE_LOGGER(logger, "Component"); +DEFINE_LOGGER(logger_xml, "Component.XML"); Component::Component(Swift::EventLoop *loop, Swift::NetworkFactories *factories, Config *config, Factory *factory, Transport::UserRegistry *userRegistry) { m_component = NULL; diff --git a/src/user.cpp b/src/user.cpp index 0baedfa9..d347f795 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -25,24 +25,23 @@ #include "transport/usermanager.h" #include "transport/conversationmanager.h" #include "transport/presenceoracle.h" +#include "transport/logging.h" #include "Swiften/Swiften.h" #include "Swiften/Server/ServerStanzaChannel.h" #include "Swiften/Elements/StreamError.h" #include "Swiften/Elements/MUCPayload.h" #include "Swiften/Elements/SpectrumErrorPayload.h" -#include "log4cxx/logger.h" #include #include #include -using namespace log4cxx; using namespace boost; #define foreach BOOST_FOREACH namespace Transport { -static LoggerPtr logger = Logger::getLogger("User"); +DEFINE_LOGGER(logger, "User"); User::User(const Swift::JID &jid, UserInfo &userInfo, Component *component, UserManager *userManager) { m_jid = jid.toBare(); diff --git a/src/usermanager.cpp b/src/usermanager.cpp index 52e41607..82371146 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -25,19 +25,18 @@ #include "transport/conversationmanager.h" #include "transport/rostermanager.h" #include "transport/userregistry.h" +#include "transport/logging.h" #include "storageresponder.h" -#include "log4cxx/logger.h" + #include "Swiften/Swiften.h" #include "Swiften/Server/ServerStanzaChannel.h" #include "Swiften/Elements/StreamError.h" #include "malloc.h" // #include "valgrind/memcheck.h" -using namespace log4cxx; - namespace Transport { -static LoggerPtr logger = Logger::getLogger("UserManager"); +DEFINE_LOGGER(logger, "UserManager"); UserManager::UserManager(Component *component, UserRegistry *userRegistry, StorageBackend *storageBackend) { m_cachedUser = NULL; diff --git a/src/userregistration.cpp b/src/userregistration.cpp index db7ab22e..0e23217f 100644 --- a/src/userregistration.cpp +++ b/src/userregistration.cpp @@ -24,18 +24,17 @@ #include "transport/transport.h" #include "transport/rostermanager.h" #include "transport/user.h" +#include "transport/logging.h" #include "Swiften/Elements/ErrorPayload.h" #include #include #include -#include "log4cxx/logger.h" using namespace Swift; -using namespace log4cxx; namespace Transport { -static LoggerPtr logger = Logger::getLogger("UserRegistration"); +DEFINE_LOGGER(logger, "UserRegistration"); UserRegistration::UserRegistration(Component *component, UserManager *userManager, StorageBackend *storageBackend) : Swift::Responder(component->m_iqRouter) { m_component = component; diff --git a/src/userregistry.cpp b/src/userregistry.cpp index 00b72135..81f6806c 100644 --- a/src/userregistry.cpp +++ b/src/userregistry.cpp @@ -23,13 +23,11 @@ #include "Swiften/Swiften.h" #include "Swiften/Server/UserRegistry.h" #include "transport/userregistry.h" -#include "log4cxx/logger.h" - -using namespace log4cxx; +#include "transport/logging.h" namespace Transport { -static LoggerPtr logger = Logger::getLogger("UserRegistry"); +DEFINE_LOGGER(logger, "UserRegistry"); UserRegistry::UserRegistry(Config *cfg, Swift::NetworkFactories *factories) { config = cfg; diff --git a/src/usersreconnecter.cpp b/src/usersreconnecter.cpp index 0ba66afb..7a7ecdfd 100644 --- a/src/usersreconnecter.cpp +++ b/src/usersreconnecter.cpp @@ -26,16 +26,14 @@ #include "Swiften/Swiften.h" #include "transport/storagebackend.h" #include "transport/transport.h" -#include "log4cxx/logger.h" - -using namespace log4cxx; +#include "transport/logging.h" using namespace Swift; using namespace boost; namespace Transport { -static LoggerPtr logger = Logger::getLogger("UserReconnecter"); +DEFINE_LOGGER(logger, "UserReconnecter"); UsersReconnecter::UsersReconnecter(Component *component, StorageBackend *storageBackend) { m_component = component; diff --git a/src/vcardresponder.cpp b/src/vcardresponder.cpp index 4277d70d..83ff2acc 100644 --- a/src/vcardresponder.cpp +++ b/src/vcardresponder.cpp @@ -28,16 +28,14 @@ #include "transport/usermanager.h" #include "transport/rostermanager.h" #include "transport/transport.h" -#include "log4cxx/logger.h" - -using namespace log4cxx; +#include "transport/logging.h" using namespace Swift; using namespace boost; namespace Transport { -static LoggerPtr logger = Logger::getLogger("VCardResponder"); +DEFINE_LOGGER(logger, "VCardResponder"); VCardResponder::VCardResponder(Swift::IQRouter *router, Swift::NetworkFactories *factories, UserManager *userManager) : Swift::Responder(router) { m_id = 0; From 143a692c8df17a57aa77f664a8895b69b76d6f38 Mon Sep 17 00:00:00 2001 From: HanzZ Date: Wed, 21 Mar 2012 16:40:20 +0100 Subject: [PATCH 3/3] Changelog --- ChangeLog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index 69a7fd12..645ca3fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,10 @@ Version 2.0.0-beta2 (2012-XX-XX): * Fixed username_mask setting. * Added new fields into statistics (backends_crashed, messages related stats). + * Log4cxx is now optional dependency. Without Log4cxx, Spectrum 2 logs + to standard output. + * Fixed crash when Log4cxx configuration file didn't exist. + * Admin can now see "Admin" contact in server-mode. libpurple: * Added support for MUC for prpl-jabber protocol.