Skip to content

Commit

Permalink
implement print config to log
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed Jul 2, 2024
1 parent f94c9bf commit 2eb1659
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
48 changes: 37 additions & 11 deletions src/tateyama/altimeter/altimeter_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
#include <altimeter/event/event_logger.h>

#include "altimeter_helper.h"
#include "logging.h"

namespace tateyama::altimeter {

altimeter_helper::altimeter_helper(tateyama::api::configuration::whole* conf) :conf_(conf) {}
altimeter_helper::altimeter_helper(tateyama::api::configuration::whole* conf) : conf_(conf) {
}

altimeter_helper::~altimeter_helper() {
shutdown();
Expand All @@ -57,25 +59,34 @@ void altimeter_helper::shutdown() {
//
// The following method is created with reference to altimeter/logger/examples/altimeter/main.cpp
//
void altimeter_helper::setup(::altimeter::configuration& configuration, tateyama::api::configuration::section* section, log_type type, const std::string& dbname) {
void altimeter_helper::setup(::altimeter::configuration& configuration, tateyama::api::configuration::section* section, log_type type, [[maybe_unused]] const std::string& dbname) {
configuration.category((type == log_type::event_log) ? ::altimeter::event::category : ::altimeter::audit::category);
configuration.output(section->get<bool>("output").value());
configuration.directory(section->get<std::filesystem::path>("directory").value().string());
auto output = section->get<bool>("output").value();
configuration.output(output);
auto directory = section->get<std::filesystem::path>("directory").value().string();
configuration.directory(directory);
auto level = section->get<int>("level").value();
configuration.level(level);
configuration.file_number(section->get<std::uint32_t>("file_number").value());
configuration.sync(section->get<bool>("sync").value());
configuration.buffer_size(section->get<std::size_t>("buffer_size").value());
configuration.flush_interval(section->get<std::size_t>("flush_interval").value());
configuration.flush_file_size(section->get<std::size_t>("flush_file_size").value());
configuration.max_file_size(section->get<std::size_t>("max_file_size").value());
auto file_number = section->get<std::uint32_t>("file_number").value();
configuration.file_number(file_number);
auto sync = section->get<bool>("sync").value();
configuration.sync(sync);
auto buffer_size = section->get<std::size_t>("buffer_size").value();
configuration.buffer_size(buffer_size);
auto flush_interval = section->get<std::size_t>("flush_interval").value();
configuration.flush_interval(flush_interval);
auto flush_file_size = section->get<std::size_t>("flush_file_size").value();
configuration.flush_file_size(flush_file_size);
auto max_file_size = section->get<std::size_t>("max_file_size").value();
configuration.max_file_size(max_file_size);

if (type == log_type::event_log) {
configuration.error_handler([](std::string_view error_message) {
std::cout << "Failed to flush or rotate event log files: "
<< error_message << "\n";
});
::altimeter::event::event_logger::set_stmt_duration_threshold(section->get<std::size_t>("stmt_duration_threshold").value());
::altimeter::event::event_logger::set_level(level, dbname);
// ::altimeter::event::event_logger::set_level(level, dbname);
} else {
configuration.error_handler([](std::string_view error_message) {
std::cout << "Failed to flush or rotate audit log files: "
Expand All @@ -93,6 +104,21 @@ void altimeter_helper::setup(::altimeter::configuration& configuration, tateyama
LOG(ERROR) << "Failed to " << log_type_name << " write: " << error_message
<< ", log: " << log << "\n";
});

// output configuration to be used
const std::string_view& prefix = (type == log_type::event_log) ? altimeter_event_config_prefix : altimeter_audit_config_prefix;
LOG(INFO) << prefix << "output = " << std::boolalpha << output << ", log output flag.";
LOG(INFO) << prefix << "directory = " << directory << ", log-storage directory path";
LOG(INFO) << prefix << "level = " << level << ", log level";
LOG(INFO) << prefix << "file_number = " << file_number << ", number of log output files";
LOG(INFO) << prefix << "sync = " << std::boolalpha << sync << ", log-synchronous storage";
LOG(INFO) << prefix << "buffer_size = " << buffer_size << ", buffer size per log file";
LOG(INFO) << prefix << "flush_interval = " << flush_interval << ", flash interval (milliseconds)";
LOG(INFO) << prefix << "flush_file_size = " << flush_file_size << ", file size to be flashed";
LOG(INFO) << prefix << "max_file_size = " << max_file_size << ", file size to rotate";
if (type == log_type::event_log) {
LOG(INFO) << prefix << "stmt_duration_threshold = " << section->get<std::size_t>("stmt_duration_threshold").value() << ", duration threshold for statement log";
}
}

} // tateyama::altimeter
2 changes: 1 addition & 1 deletion src/tateyama/altimeter/altimeter_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ namespace tateyama::altimeter {
void shutdown();

private:
tateyama::api::configuration::whole* conf_;
std::vector<::altimeter::configuration> cfgs_ = {
::altimeter::configuration{}, // event_log_cfg
::altimeter::configuration{} // audit_log_cfg
};
bool shutdown_{};
tateyama::api::configuration::whole* conf_{};

void setup(::altimeter::configuration& configuration, tateyama::api::configuration::section* section, log_type type, const std::string& dbname = "");
};
Expand Down
24 changes: 24 additions & 0 deletions src/tateyama/altimeter/logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2018-2024 Project Tsurugi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

namespace tateyama::altimeter {

static constexpr std::string_view altimeter_event_config_prefix = "/:altimeter:event:config: ";

static constexpr std::string_view altimeter_audit_config_prefix = "/:altimeter:audit:config: ";

} // namespace

0 comments on commit 2eb1659

Please sign in to comment.