Skip to content

Commit

Permalink
Replace google-log with log4cplus.
Browse files Browse the repository at this point in the history
Since google-glog were dropped from standard Ubuntu repositories in 12.04, this ensures bithorde compiles without external deps on Ubuntu.
  • Loading branch information
rawler committed May 18, 2012
1 parent 0104766 commit 49e4dfe
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 95 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion bithorded/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ADD_EXECUTABLE(bithorded

TARGET_LINK_LIBRARIES(bithorded
${Boost_LIBRARIES}
${GLOG_LIBRARIES}
${LOG4CPLUS_LIBRARIES}
bithorde
)

Expand Down
7 changes: 3 additions & 4 deletions bithorded/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
#include <iostream>

#include <crypto++/files.h>
#include <log4cplus/configurator.h>

#include "buildconf.hpp"
#include "lib/hashes.h"
#include "store/linkedassetstore.hpp"
#include "server/config.hpp"
#include "server/server.hpp"

#include <glog/logging.h>

using namespace std;
namespace asio = boost::asio;
namespace fs = boost::filesystem;
Expand All @@ -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);
Expand Down
15 changes: 10 additions & 5 deletions bithorded/router/asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
9 changes: 7 additions & 2 deletions bithorded/router/router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
23 changes: 14 additions & 9 deletions bithorded/server/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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());

Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions bithorded/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 9 additions & 4 deletions bithorded/store/linkedassetstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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),
Expand Down Expand Up @@ -171,15 +176,15 @@ 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:
return boost::make_shared<SourceAsset>(assetFolder);
break;

case BROKEN:
LOG(WARNING) << "broken asset detected, " << assetFolder << endl;
LOG4CPLUS_WARN(storeLog, "broken asset detected, " << assetFolder);
purgeLinkAndAsset(referrer);
default:
break;
Expand All @@ -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)));
}
}
Expand Down
2 changes: 1 addition & 1 deletion clients/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ SET_TARGET_PROPERTIES(bhfuse PROPERTIES
)
TARGET_LINK_LIBRARIES ( bhfuse
bithorde
${GLOG_LIBRARIES}
${LOG4CPLUS_LIBRARIES}
${Boost_LIBRARIES}
${FUSE_LIBRARIES}
)
Expand Down
13 changes: 9 additions & 4 deletions clients/bhfuse/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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();
}
}
Expand All @@ -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;

Expand Down
Loading

0 comments on commit 49e4dfe

Please sign in to comment.