Skip to content

Commit

Permalink
[Feature] File sink with move rotation registration.
Browse files Browse the repository at this point in the history
File sink with move rotation watcher can now be registered via repository.
  • Loading branch information
3Hren committed Sep 24, 2014
1 parent 7c4717d commit 9887fe2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/blackhole/sink/files.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,14 @@ struct unique_id_traits<sink::files_t<Backend, sink::rotator_t<Backend, Watcher>
if (rotation_it != cfg.end()) {
const dynamic_t::object_t& rotation = rotation_it->second.to<dynamic_t::object_t>();

const bool has_move_watcher = rotation.find("move") != rotation.end();
const bool has_size_watcher = rotation.find("size") != rotation.end();
const bool has_datetime_watcher = rotation.find("period") != rotation.end();

if (has_move_watcher) {
return utils::format("%s/%s/%s", sink_type::name(), rotator_type::name(), "move");
}

if (has_size_watcher && has_datetime_watcher) {
throw blackhole::error_t("set watcher is not implemented yet");
} else if (has_size_watcher) {
Expand Down Expand Up @@ -213,6 +218,18 @@ struct factory_traits<sink::files_t<Backend>> {
}
};

template<class Backend>
struct factory_traits<sink::files_t<Backend, sink::rotator_t<Backend, sink::rotation::watcher::move_t>>> {
typedef sink::rotation::watcher::move_t watcher_type;
typedef sink::rotator_t<Backend, watcher_type> rotator_type;
typedef sink::files_t<Backend, rotator_type> sink_type;
typedef typename sink_type::config_type config_type;

static void map_config(const aux::extractor<sink_type>& ex, config_type& config) {
aux::filler<sink_type>::extract_to(ex, config);
}
};

template<class Backend>
struct factory_traits<sink::files_t<Backend, sink::rotator_t<Backend, sink::rotation::watcher::size_t>>> {
typedef sink::rotation::watcher::size_t watcher_type;
Expand Down
24 changes: 24 additions & 0 deletions src/tests/test_FactoryInitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ TEST(Factory, FileStringsFrontend) {
EXPECT_TRUE(bool(factory.create(formatter, sink)));
}

TEST(Repository, RotationFileStringsFrontendWithMoveWatcher) {
external_factory_t factory;
factory.add<
sink::files_t<
sink::files::boost_backend_t,
sink::rotator_t<
sink::files::boost_backend_t,
sink::rotation::watcher::move_t
>
>,
formatter::string_t
>();

formatter_config_t formatter("string");
formatter["pattern"] = "[%(timestamp)s]: %(message)s";

sink_config_t sink("files");
sink["path"] = "/dev/stdout";
sink["autoflush"] = true;
sink["rotation"]["move"] = true;

EXPECT_TRUE(bool(factory.create(formatter, sink)));
}

TEST(Repository, RotationFileStringsFrontendWithSizeWatcher) {
external_factory_t factory;
factory.add<
Expand Down

0 comments on commit 9887fe2

Please sign in to comment.