Skip to content

Commit

Permalink
An ability to pick the Logging Service backend.
Browse files Browse the repository at this point in the history
Conflicts:
	include/cocaine/api/logger.hpp
	include/cocaine/detail/services/logging.hpp
	src/services/logging.cpp
  • Loading branch information
Andrey Sibiryov committed Nov 26, 2013
1 parent ef32d65 commit bac7de9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/cocaine/detail/services/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class logging_t:
{
public:
logging_t(context_t& context, io::reactor_t& reactor, const std::string& name, const Json::Value& args);

private:
std::unique_ptr<api::logger_t> m_logger;
};

}} // namespace cocaine::service
Expand Down
20 changes: 17 additions & 3 deletions src/services/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "cocaine/detail/services/logging.hpp"

#include "cocaine/api/logger.hpp"

#include "cocaine/context.hpp"
#include "cocaine/logging.hpp"
#include "cocaine/messages.hpp"
Expand All @@ -32,11 +34,23 @@ using namespace std::placeholders;
logging_t::logging_t(context_t& context, io::reactor_t& reactor, const std::string& name, const Json::Value& args):
category_type(context, reactor, name, args)
{
auto logger = std::ref(context.logger());
auto backend = args.get("backend", "core").asString();

if(backend != "core") {
const auto it = context.config.loggers.find(backend);

if(it == context.config.loggers.end()) {
throw cocaine::error_t("the '%s' logger is not configured", backend);
}

m_logger = context.get<api::logger_t>(it->second.type, context.config, it->second.args);
}

using cocaine::logging::logger_concept_t;

on<io::logging::emit>("emit", std::bind(&logger_concept_t::emit, logger, _1, _2, _3));
on<io::logging::verbosity>("verbosity", std::bind(&logger_concept_t::verbosity, logger));
logger_concept_t* ptr = m_logger ? m_logger.get() : &context.logger();

on<io::logging::emit>("emit", std::bind(&logger_concept_t::emit, ptr, _1, _2, _3));
on<io::logging::verbosity>("verbosity", std::bind(&logger_concept_t::verbosity, ptr));
}

0 comments on commit bac7de9

Please sign in to comment.