diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c1ef558ede3edc7d08860e2753f467f3479099b..78c29c7487401d4cae884921b77024c92013b239 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/ChangeLog b/ChangeLog index 69a7fd121132c28a35bac8b0934e5d38d2a50229..645ca3fa7e83a47d71c9d1416ebebf91733db0a4 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. diff --git a/backends/libcommuni/main.cpp b/backends/libcommuni/main.cpp index 6443c2bd6420a29e9b5bf23dc02cbbcd1fe5a278..9b717d4ca7ebb2ccea6ee3f165b06905d808d7bc 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 971c2c0c353308b88f6342ccabb4d454369cade7..ac972b5fab5f8f7aa5e0088a71a6eace7e5a04ca 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 06bd378ce18c8c0abc19cbae95b0a8226cb900b1..f668e5438b7f498025e6cf63df360af037c086b5 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 b32c893d850a4f8ed18f1594bedf2e02b6a4f8be..1dacea4005fef70baecd32b309764e0c1c99d8c4 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 8c9c7b4810774207b4f35771a3b3d44ad22b95d8..c971f2735d0c79eda07ca73544695490b482537d 100644 --- a/backends/libpurple/main.cpp +++ b/backends/libpurple/main.cpp @@ -6,14 +6,10 @@ #include #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" @@ -31,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; @@ -1648,44 +1643,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/backends/skype/main.cpp b/backends/skype/main.cpp index 6329ef46431355175be5681678db79c995c9d73d..aa237178261657a5c1c42d07762d90ec8bec1ba9 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 a6502bdc23297d9e8df3e3612281569dee6c0a12..2e61868c60f906925a1c0fd76452f62271e1697a 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 44fc86237e1ae10824de23377be3b22f6eebd97d..595ce42d19cde6e8e3ae865758d6d664992b4eb7 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 ebf798be0a02b6f271fcc5aa51e13f949ceceb61..40218daa0e7a6367f445f6d91a69d587b6174fbd 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 79b1dfd5e77f3a25918ddd9184887533f8f6603d..4abf92dd5058954f4de34423b05ac716c58ccf2b 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/CMakeLists.txt b/plugin/cpp/CMakeLists.txt index 544e2ec2d07a3b29356597ca969f99d1e43d0b06..b41b3453bb54be6341eb3ef138a6816c2240ead3 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/plugin/cpp/networkplugin.cpp b/plugin/cpp/networkplugin.cpp index 1b7f448c12198bf9d2c622194b873e1d12e149a6..179b2f0829ad7a9cb782b3971fcd7851b7ae6993 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 be525f60f005232215653b0674fabfb9987b16b8..82540d1124573ce29e389f51f262c5b3076e3093 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 cec4dfa6f7e0b69f97e8b60599b1828085b0d382..c79db37cb78b1f2e54999ed476206ea6d9d0f523 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 9737907aa56e066ee72385da57580251e42b6c06..708fec439c9e9388ab29641c5629b1029b18ea67 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/config.cpp b/src/config.cpp index 7088889c182bab346ff438ce62b984834e05ce74..5962cc2548a788f499ce1ce6f91f4eeed7999951 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)); } diff --git a/src/conversation.cpp b/src/conversation.cpp index d903e320a50b10b7638feb8e9a44539177f82c2a..571a4cde4b3c3a804b3603d8deb007fe57dd2100 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 bc08d7a7856c11ab3408aa29b194fd529e1d9f84..6a5d7d1615bdb3083b501d78540542a2c66429a0 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 8fcacdcfb2ce61a6e1a7578bbffe22148ac6409e..73c08a86459faa1c1d80f40325586506df673229 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 903c069aed6317ece134a0f789630929b2bbdc90..2f7c0c352aabb335d31336f7c069677807f3e7c4 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 fc9f94b3b832165819a10303d6dea8479f782b52..3d56878f8161f23845ebb1e40c8e8de4dc6798e1 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 1c74ec3e7f3c168e5ce44c50ff7f0c18a7053715..83514ada59643f09000ee1de008846bdf79e53cf 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 1af53c3a430a542831e7eae1fdf9d82edc98b45b..9bb5eaef76679f4d90feaec5b7c6ce8a40ed46d0 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 00f601d76df396bf77d47e0c64a92362b5b8581f..90d66759a489ada2e66e185c73ce7ba0e5fdbedb 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 1bde017318445eb439495dc55ac744e47900298b..ea49430b08beb5b3922ab044695c85471a6cccd0 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 fe243bcc7585356bd9a6b03b152128b63de58341..3b0c4612661438094ec3be69b7d96f248072187c 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 c61ca628df1f04b0faf28991c54cddc5284fe781..e9a11dac8b0251d4374288a34379169f5556e810 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 bf4e4b5fcb1bc0b176baf8c2ffbf5e5f28d33424..4ba24e71e20e32610c670047db6f4514a2416b23 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 b5f4e5aabe99d293521e417382dad4c361d132cc..1b3d2aa95598ceaddcce08a0bb5951b77410797e 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 55ba41ae083c9cb05e914193878a3f3c29596a33..aea740f0279c6ee91d57c32f3e289eb77d2a95f6 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 8eab7bf7970ce788d7a94dee601e0832e4070d6b..581670af651dbf1bf950248ee19c41ebda25a0d8 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 0baedfa98cdb08779a3b233e795d8a94d043757c..d347f79517ace88f110f23d11290b7013983f935 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 52e4160755681c641d5691dbb5bf5f7fb57dd506..823711469593fe48fe00afd92b074f9369b2e4cc 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 db7ab22e97d8ff95e9d3cd94653799679b2c0ff0..0e23217fba8be7f4bfa844af640850b462f204ce 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 00b72135719b13b96f64d14f8dc792b24bb8cb14..81f6806ce1867feb5722186a9a92a4e014242e1e 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 0ba66afb3914f6ca58a6a9597907554b7dfc99f7..7a7ecdfdeac5ea50fabf3ac23ba473673c3948c0 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 4277d70d3d4a7e5a791ccffcab03c163ecca600b..83ff2acc275ec306bb0ac3ea4371bdfa5eaa6849 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;