Skip to content
Browse files

Replace google-log with log4cplus.

Since google-glog were dropped from standard Ubuntu repositories in 12.04, this ensures bithorde compiles without external deps on Ubuntu.
  • Loading branch information...
1 parent 0104766 commit 49e4dfee7a347f677f011558119a15590485339d @rawler committed
View
6 CMakeLists.txt
@@ -64,9 +64,9 @@ SET(PROTOBUF_REQUIRE_CPP TRUE)
FIND_PACKAGE(ProtocolBuffers REQUIRED)
INCLUDE_DIRECTORIES (${PROTOC_OUT_DIR}) # For generated protobuf headers.
-# Setup the glog package
-FIND_PACKAGE(Glog REQUIRED)
-INCLUDE_DIRECTORIES(${GLOG_INCLUDE_DIRS})
+# Setup the logging package
+FIND_PACKAGE(Log4cplus REQUIRED)
+INCLUDE_DIRECTORIES(${LOG4CLPUS_INCLUDE_DIRS})
FIND_PACKAGE(PkgConfig REQUIRED)
View
2 README
@@ -37,7 +37,7 @@ Build requirements (Ubuntu Package Names)
libboost-all-dev (>= 1.46, might work with earlier, may not need all modules)
libcrypto++-dev
libfuse-dev
- libgoogle-glog-dev
+ liblog4cplus-dev
libprotobuf-dev
pkg-config
View
2 bithorded/CMakeLists.txt
@@ -25,7 +25,7 @@ ADD_EXECUTABLE(bithorded
TARGET_LINK_LIBRARIES(bithorded
${Boost_LIBRARIES}
- ${GLOG_LIBRARIES}
+ ${LOG4CPLUS_LIBRARIES}
bithorde
)
View
7 bithorded/main.cpp
@@ -5,6 +5,7 @@
#include <iostream>
#include <crypto++/files.h>
+#include <log4cplus/configurator.h>
#include "buildconf.hpp"
#include "lib/hashes.h"
@@ -12,8 +13,6 @@
#include "server/config.hpp"
#include "server/server.hpp"
-#include <glog/logging.h>
-
using namespace std;
namespace asio = boost::asio;
namespace fs = boost::filesystem;
@@ -22,8 +21,8 @@ namespace po = boost::program_options;
using namespace bithorded;
int main(int argc, char* argv[]) {
- google::InitGoogleLogging(argv[0]);
- google::LogToStderr();
+ log4cplus::BasicConfigurator config;
+ config.configure();
try {
Config cfg(argc, argv);
View
15 bithorded/router/asset.cpp
@@ -21,11 +21,16 @@
#include <boost/smart_ptr/make_shared.hpp>
#include <utility>
-#include <glog/logging.h>
+#include <log4cplus/logger.h>
+#include <log4cplus/loggingmacros.h>
using namespace bithorded::router;
using namespace std;
+namespace bithorded { namespace router {
+ log4cplus::Logger assetLogger = log4cplus::Logger::getInstance("router");
+} }
+
bool bithorded::router::ForwardedAsset::hasUpstream(const std::string peername)
{
return _upstream.count(peername);
@@ -52,19 +57,19 @@ void bithorded::router::ForwardedAsset::bindUpstreams(const std::map< string, bi
void bithorded::router::ForwardedAsset::onUpstreamStatus(const string& peername, const bithorde::AssetStatus& status)
{
if (status.status() == bithorde::Status::SUCCESS) {
- DLOG(INFO) << "Found upstream " << peername;
+ LOG4CPLUS_DEBUG(assetLogger, "Found upstream " << peername);
if (status.has_size()) {
if (_size == -1) {
_size = status.size();
} else if (_size != (int64_t)status.size()) {
- LOG(WARNING) << peername << " responded with mismatching size, ignoring...";
+ LOG4CPLUS_WARN(assetLogger, peername << " responded with mismatching size, ignoring...");
_upstream.erase(peername);
}
} else {
- LOG(WARNING) << peername << " SUCCESS response not accompanied with asset-size.";
+ LOG4CPLUS_WARN(assetLogger, peername << " SUCCESS response not accompanied with asset-size.");
}
} else {
- DLOG(INFO) << "Failed upstream " << peername;
+ LOG4CPLUS_DEBUG(assetLogger, "Failed upstream " << peername);
_upstream.erase(peername);
}
updateStatus();
View
9 bithorded/router/router.cpp
@@ -22,7 +22,8 @@
#include <boost/lexical_cast.hpp>
#include <boost/make_shared.hpp>
-#include <glog/logging.h>
+#include <log4cplus/logger.h>
+#include <log4cplus/loggingmacros.h>
#include "../server/server.hpp"
@@ -33,6 +34,10 @@ using namespace std;
const boost::posix_time::seconds RECONNECT_INTERVAL(5);
+namespace bithorded { namespace router {
+ log4cplus::Logger routerLog = log4cplus::Logger::getInstance("router");
+} }
+
class bithorded::router::FriendConnector : public boost::enable_shared_from_this<bithorded::router::FriendConnector> {
Server& _server;
boost::shared_ptr<boost::asio::ip::tcp::socket> _socket;
@@ -106,7 +111,7 @@ void Router::onConnected(const bithorded::Client::Ptr& client )
{
string peerName = client->peerName();
if (_friends.count(peerName)) {
- LOG(INFO) << "Friend " << peerName << " connected" << endl;
+ LOG4CPLUS_INFO(routerLog, "Friend " << peerName << " connected");
if (_connectors[peerName].get())
_connectors[peerName]->cancel();
_connectors.erase(peerName);
View
23 bithorded/server/client.cpp
@@ -19,7 +19,8 @@
#include <boost/assert.hpp>
#include <iostream>
-#include <glog/logging.h>
+#include <log4cplus/logger.h>
+#include <log4cplus/loggingmacros.h>
#include "server.hpp"
#include "../../lib/magneturi.h"
@@ -33,6 +34,10 @@ namespace fs = boost::filesystem;
using namespace bithorded;
+namespace bithorded {
+ log4cplus::Logger clientLogger = log4cplus::Logger::getInstance("client");
+}
+
Client::Client( Server& server) :
bithorde::Client(server.ioService(), server.name()),
_server(server)
@@ -54,7 +59,7 @@ bool Client::requestsAsset(const BitHordeIds& ids) {
void Client::onMessage(const bithorde::HandShake& msg)
{
bithorde::Client::onMessage(msg);
- LOG(INFO) << "Connected: " << msg.name() << endl;
+ LOG4CPLUS_INFO(clientLogger, "Connected: " << msg.name());
}
void Client::onMessage(const bithorde::BindWrite& msg)
@@ -66,15 +71,15 @@ void Client::onMessage(const bithorde::BindWrite& msg)
fs::path path(msg.linkpath());
if (path.is_absolute()) {
if (_server.linkAsset(path, boost::bind(&Client::onLinkHashDone, shared_from_this(), h, _1))) {
- LOG(INFO) << "Hashing " << path << endl;
+ LOG4CPLUS_INFO(clientLogger, "Linking " << path);
resp.set_status(bithorde::SUCCESS);
} else {
- LOG(ERROR) << "Upload did not match any allowed assetStore: " << path << endl;
+ LOG4CPLUS_ERROR(clientLogger, "Upload did not match any allowed assetStore: " << path);
resp.set_status(bithorde::ERROR);
}
}
} else {
- LOG(ERROR) << "Sorry, upload isn't supported yet" << endl;
+ LOG4CPLUS_ERROR(clientLogger, "Sorry, upload isn't supported yet");
resp.set_status(bithorde::ERROR);
}
sendMessage(bithorde::Connection::AssetStatus, resp);
@@ -85,7 +90,7 @@ void Client::onMessage(bithorde::BindRead& msg)
bithorde::Asset::Handle h = msg.handle();
if (msg.ids_size() > 0) {
// Trying to open
- LOG(INFO) << peerName() << ':' << h << " requested: " << MagnetURI(msg) << endl;
+ LOG4CPLUS_INFO(clientLogger, peerName() << ':' << h << " requested: " << MagnetURI(msg));
if (!msg.has_uuid())
msg.set_uuid(rand64());
@@ -108,7 +113,7 @@ void Client::onMessage(bithorde::BindRead& msg)
}
} else {
// Trying to close
- LOG(INFO) << peerName() << ':' << h << " closed" << endl;
+ LOG4CPLUS_INFO(clientLogger, peerName() << ':' << h << " closed");
clearAsset(h);
informAssetStatus(h, bithorde::NOTFOUND);
}
@@ -169,7 +174,7 @@ void Client::informAssetStatusUpdate(bithorde::Asset::Handle h, const bithorded:
} else {
resp.set_status(bithorde::NOTFOUND);
}
- LOG(INFO) << peerName() << ':' << h << " new state " << bithorde::Status_Name(resp.status()) << endl;
+ LOG4CPLUS_INFO(clientLogger, peerName() << ':' << h << " new state " << bithorde::Status_Name(resp.status()));
sendMessage(bithorde::Connection::AssetStatus, resp);
}
@@ -193,7 +198,7 @@ bool Client::assignAsset(bithorde::Asset::Handle handle_, const Asset::Ptr& a)
size_t handle = handle_;
if (handle >= _assets.size()) {
if (handle > MAX_ASSETS) {
- LOG(ERROR) << peerName() << ": handle larger than allowed limit (" << handle << " < " << MAX_ASSETS << ")" << endl;
+ LOG4CPLUS_ERROR(clientLogger, peerName() << ": handle larger than allowed limit (" << handle << " < " << MAX_ASSETS << ")");
return false;
}
size_t new_size = _assets.size() + (handle - _assets.size() + 1) * 2;
View
9 bithorded/server/server.cpp
@@ -25,7 +25,8 @@
#include "client.hpp"
#include "config.hpp"
-#include <glog/logging.h>
+#include <log4cplus/logger.h>
+#include <log4cplus/loggingmacros.h>
using namespace std;
@@ -34,6 +35,10 @@ namespace fs = boost::filesystem;
using namespace bithorded;
+namespace bithorded {
+ log4cplus::Logger serverLog = log4cplus::Logger::getInstance("server");
+}
+
BindError::BindError(bithorde::Status status):
runtime_error("findAsset failed with " + bithorde::Status_Name(status)),
status(status)
@@ -134,7 +139,7 @@ void Server::clientAuthenticated(const bithorded::Client::WeakPtr& client_) {
void Server::clientDisconnected(bithorded::Client::Ptr& client)
{
- LOG(INFO) << "Disconnected: " << client->peerName() << endl;
+ LOG4CPLUS_INFO(serverLog, "Disconnected: " << client->peerName());
_router.onDisconnected(client);
// Will destroy the client, unless others are holding references.
client.reset();
View
13 bithorded/store/linkedassetstore.cpp
@@ -23,7 +23,8 @@
#include <time.h>
#include <utime.h>
-#include <glog/logging.h>
+#include <log4cplus/logger.h>
+#include <log4cplus/loggingmacros.h>
using namespace std;
@@ -37,6 +38,10 @@ const fs::path TIGER_DIR = ".bh_meta/tiger";
const int THREADPOOL_CONCURRENCY = 4;
+namespace bithorded {
+ log4cplus::Logger storeLog = log4cplus::Logger::getInstance("store");
+}
+
LinkedAssetStore::LinkedAssetStore(boost::asio::io_service& ioSvc, const boost::filesystem3::path& baseDir) :
_threadPool(THREADPOOL_CONCURRENCY),
_ioSvc(ioSvc),
@@ -171,7 +176,7 @@ SourceAsset::Ptr openAssetFolder(const fs::path& referrer, const fs::path& asset
auto assetDataPath = assetFolder/"data";
switch (validateDataSymlink(assetDataPath)) {
case OUTDATED:
- LOG(WARNING) << "outdated asset detected, " << assetFolder << endl;
+ LOG4CPLUS_WARN(storeLog, "outdated asset detected, " << assetFolder);
purgeLink(referrer);
fs::remove(referrer/"meta");
case OK:
@@ -179,7 +184,7 @@ SourceAsset::Ptr openAssetFolder(const fs::path& referrer, const fs::path& asset
break;
case BROKEN:
- LOG(WARNING) << "broken asset detected, " << assetFolder << endl;
+ LOG4CPLUS_WARN(storeLog, "broken asset detected, " << assetFolder);
purgeLinkAndAsset(referrer);
default:
break;
@@ -203,7 +208,7 @@ SourceAsset::Ptr LinkedAssetStore::_openTiger(const std::string& tigerId)
_tigerMap[tigerId] = asset;
} else {
asset.reset();
- LOG(WARNING) << "Unhashed asset detected, hashing" << endl;
+ LOG4CPLUS_WARN(storeLog, "Unhashed asset detected, hashing");
_threadPool.post(*new HashTask(asset, _ioSvc, boost::bind(&LinkedAssetStore::_addAsset, this, _1, &noop)));
}
}
View
2 clients/CMakeLists.txt
@@ -37,7 +37,7 @@ SET_TARGET_PROPERTIES(bhfuse PROPERTIES
)
TARGET_LINK_LIBRARIES ( bhfuse
bithorde
- ${GLOG_LIBRARIES}
+ ${LOG4CPLUS_LIBRARIES}
${Boost_LIBRARIES}
${FUSE_LIBRARIES}
)
View
13 clients/bhfuse/main.cpp
@@ -4,7 +4,9 @@
#include <errno.h>
#include <signal.h>
-#include <glog/logging.h>
+#include <log4cplus/logger.h>
+#include <log4cplus/loggingmacros.h>
+#include <log4cplus/configurator.h>
#include "buildconf.hpp"
@@ -19,16 +21,17 @@ static asio::io_service ioSvc;
using namespace bithorde;
+log4cplus::Logger sigLogger = log4cplus::Logger::getInstance("signal");
bool terminating = false;
void sigint(int sig) {
- LOG(INFO) << "Intercepted signal#" << sig;
+ LOG4CPLUS_INFO(sigLogger, "Intercepted signal#" << sig);
if (sig == SIGINT) {
if (terminating) {
- LOG(INFO) << "Exiting...";
+ LOG4CPLUS_INFO(sigLogger, "Force Exiting...");
exit(-1);
} else {
terminating = true;
- LOG(INFO) << "Exiting...";
+ LOG4CPLUS_INFO(sigLogger, "Cleanly Exiting...");
ioSvc.stop();
}
}
@@ -37,6 +40,8 @@ void sigint(int sig) {
int main(int argc, char *argv[])
{
signal(SIGINT, &sigint);
+ log4cplus::BasicConfigurator config;
+ config.configure();
BoostAsioFilesystem_Options opts;
View
59 cmake/FindGlog.cmake
@@ -1,59 +0,0 @@
-# Try to find the libglog libraries
-# Once done this will define :
-#
-# Glog_FOUND - system has libglog
-# Glog_INCLUDE_DIRS - the libglog include directory
-# Glog_LIBRARIES - libglog library
-
-# Inputs to this module:
-# GLOG_ROOT The preferred installation prefix for searching for glog. Set
-# this if the module has problems finding the proper glog installation.
-
-# If GLOG_ROOT was defined in the environment, use it.
-IF (NOT GLOG_ROOT AND NOT $ENV{GLOG_ROOT} STREQUAL "")
- SET(GLOG_ROOT $ENV{GLOG_ROOT})
-ENDIF(NOT GLOG_ROOT AND NOT $ENV{GLOG_ROOT} STREQUAL "")
-IF( GLOG_ROOT )
- file(TO_CMAKE_PATH ${GLOG_ROOT} GLOG_ROOT)
-ENDIF( GLOG_ROOT )
-
-SET (GLOG_INCLUDE_DIRS)
-SET (GLOG_LIBRARIES)
-IF(WIN32)
- IF(MSVC)
- FIND_PATH(GLOG_INCLUDE_DIRS NAMES src/windows/glog/logging.h HINTS ${GLOG_ROOT})
- IF(GLOG_INCLUDE_DIRS)
- SET(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIRS}/src/windows)
- ENDIF(GLOG_INCLUDE_DIRS)
-
- IF (CMAKE_BUILD_TYPE STREQUAL "Release")
- message (STATUS " searching ${GLOG_ROOT}/Release/libglog.lib ...")
- FIND_LIBRARY(GLOG_LIBRARIES NAMES libglog.lib HINTS ${GLOG_ROOT}/Release $ENV{LIB} PATH_SUFFIXES ".lib")
- ELSE (CMAKE_BUILD_TYPE STREQUAL "Release")
- message (STATUS " searching ${GLOG_ROOT}/Debug/libglog.lib ...")
- FIND_LIBRARY(GLOG_LIBRARIES NAMES libglog.lib HINTS ${GLOG_ROOT}/Debug $ENV{LIB} PATH_SUFFIXES ".lib")
- ENDIF (CMAKE_BUILD_TYPE STREQUAL "Release")
- ELSE(MSVC)
- SET(Glog_FOUND FALSE)
- message (STATUS " Crap. this module supports only MSVC in Windows.")
- ENDIF(MSVC)
-ELSE(WIN32)
- FIND_PATH(GLOG_INCLUDE_DIRS NAMES glog/logging.h PATHS ${GLOG_ROOT}/include ${GLOG_ROOT} /include/ /usr/include/ /usr/local/include/)
- FIND_LIBRARY(GLOG_LIBRARIES NAMES glog PATHS ${GLOG_ROOT}/lib ${GLOG_ROOT} /lib /usr/lib /usr/local/lib)
-ENDIF(WIN32)
-
-IF(GLOG_INCLUDE_DIRS AND GLOG_LIBRARIES)
- SET(Glog_FOUND TRUE)
- message (STATUS " glog found in include=${GLOG_INCLUDE_DIRS},lib=${GLOG_LIBRARIES}")
-ELSE(GLOG_INCLUDE_DIRS AND GLOG_LIBRARIES)
- SET(Glog_FOUND FALSE)
- message (STATUS " glog not found. Please set GLOG_ROOT to the root directory containing glog.")
- IF(GLOG_INCLUDE_DIRS)
- message (STATUS " include=${GLOG_INCLUDE_DIRS}, but lib not found")
- ENDIF(GLOG_INCLUDE_DIRS)
- IF(GLOG_LIBRARIES)
- message (STATUS " lib=${GLOG_LIBRARIES}, but include not found")
- ENDIF(GLOG_LIBRARIES)
-ENDIF(GLOG_INCLUDE_DIRS AND GLOG_LIBRARIES)
-
-MARK_AS_ADVANCED(GLOG_INCLUDE_DIRS GLOG_LIBRARIES)
View
24 cmake/FindLog4cplus.cmake
@@ -0,0 +1,24 @@
+# - Try to find Log4cplus
+# Once done this will define
+# LOG4CPLUS_FOUND - System has Log4cplus
+# LOG4CPLUS_INCLUDE_DIRS - The Log4cplus include directories
+# LOG4CPLUS_LIBRARIES - The libraries needed to use Log4cplus
+
+
+find_path(LOG4CPLUS_INCLUDE_DIR log4cplus/config.hxx
+ PATH_SUFFIXES log4cplus )
+
+find_library(LOG4CPLUS_LIBRARY NAMES log4cplus
+ PATHS /usr)
+
+set(LOG4CPLUS_LIBRARIES ${LOG4CPLUS_LIBRARY} )
+set(LOG4CPLUS_INCLUDE_DIRS ${LOG4CPLUS_INCLUDE_DIR} )
+
+include(FindPackageHandleStandardArgs)
+
+# handle the QUIETLY and REQUIRED arguments and set LOG4CPLUS_FOUND to TRUE
+# if all listed variables are TRUE
+find_package_handle_standard_args(Log4cplus DEFAULT_MSG
+ LOG4CPLUS_LIBRARY LOG4CPLUS_INCLUDE_DIR)
+
+mark_as_advanced(LOG4CPLUS_INCLUDE_DIR LOG4CPLUS_LIBRARY)

0 comments on commit 49e4dfe

Please sign in to comment.
Something went wrong with that request. Please try again.