-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from project-tsurugi/wip/i_500_altimeter_log_…
…output implement altimeter log setup
- Loading branch information
Showing
6 changed files
with
220 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include <filesystem> | ||
|
||
#include <glog/logging.h> | ||
|
||
#include <tateyama/api/configuration.h> | ||
#include <tateyama/altimeter/events.h> | ||
#include <altimeter/logger.h> | ||
|
||
#include "altimeter_helper.h" | ||
|
||
namespace tateyama::altimeter { | ||
|
||
altimeter_helper::altimeter_helper(tateyama::api::configuration::whole* conf) { | ||
setup(cfgs_.at(0), conf->get_section("event_log"), log_type::event_log); | ||
setup(cfgs_.at(1), conf->get_section("audit_log"), log_type::audit_log); | ||
} | ||
|
||
altimeter_helper::~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) { | ||
configuration.category((type == log_type::event_log) ? log_category::event : log_category::audit); | ||
configuration.output(section->get<bool>("output").value()); | ||
configuration.directory(section->get<std::filesystem::path>("directory").value().string()); | ||
configuration.level(section->get<int>("level").value()); | ||
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()); | ||
|
||
std::string_view log_type_name = (type == log_type::event_log) ? "event log" : "audit log"; | ||
configuration.error_handler([log_type_name](std::string_view error_message) { | ||
LOG(ERROR) << "Failed to flush or rotate " << log_type_name << " files: " | ||
<< error_message << "\n"; | ||
}); | ||
configuration.log_write_error_handler( | ||
[log_type_name](std::string_view error_message, std::string_view log) { | ||
LOG(ERROR) << "Failed to " << log_type_name << " write: " << error_message | ||
<< ", log: " << log << "\n"; | ||
}); | ||
} | ||
|
||
void altimeter_helper::start() { | ||
::altimeter::logger::start(cfgs_); | ||
} | ||
|
||
void altimeter_helper::shutdown() { | ||
if (!shutdown_) { | ||
::altimeter::logger::shutdown(); | ||
shutdown_ = true; | ||
} | ||
} | ||
|
||
} // tateyama::altimeter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2018-2023 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 | ||
|
||
#include <vector> | ||
|
||
#include <tateyama/api/configuration.h> | ||
#include <altimeter/configuration.h> | ||
|
||
namespace tateyama::altimeter { | ||
|
||
class altimeter_helper { | ||
enum class log_type : std::uint32_t { | ||
/** | ||
* @brief event log. | ||
*/ | ||
event_log = 0, | ||
|
||
/** | ||
* @brief audit log. | ||
*/ | ||
audit_log = 1 | ||
}; | ||
|
||
public: | ||
/** | ||
* @brief default constructer is deleted | ||
*/ | ||
altimeter_helper() = delete; | ||
|
||
/** | ||
* @brief create a object reflects the configuration | ||
*/ | ||
explicit altimeter_helper(tateyama::api::configuration::whole* conf); | ||
|
||
/** | ||
* @brief destruct the object | ||
*/ | ||
~altimeter_helper(); | ||
|
||
altimeter_helper(altimeter_helper const& other) = delete; | ||
altimeter_helper& operator=(altimeter_helper const& other) = delete; | ||
altimeter_helper(altimeter_helper&& other) noexcept = delete; | ||
altimeter_helper& operator=(altimeter_helper&& other) noexcept = delete; | ||
|
||
/** | ||
* @brief start an altimeter logger | ||
*/ | ||
void start(); | ||
|
||
/** | ||
* @brief shutdown the altimeter logger | ||
*/ | ||
void shutdown(); | ||
|
||
private: | ||
std::vector<::altimeter::configuration> cfgs_ = { | ||
::altimeter::configuration{}, // event_log_cfg | ||
::altimeter::configuration{} // audit_log_cfg | ||
}; | ||
bool shutdown_{}; | ||
|
||
void setup(::altimeter::configuration& configuration, tateyama::api::configuration::section* section, log_type type); | ||
}; | ||
|
||
} // tateyama::altimeter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters