-
Notifications
You must be signed in to change notification settings - Fork 1
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 #167 from project-tsurugi/wip/i_500_altimeter_log_…
…output implement altimeter log output for session start and end
- Loading branch information
Showing
10 changed files
with
182 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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 | ||
|
||
// | ||
// The following uses the same style as altimeter/logger/examples/altimeter/main.cpp | ||
// | ||
namespace tateyama::altimeter { | ||
// log category list | ||
namespace log_category { | ||
static constexpr std::string_view event = "event"; | ||
static constexpr std::string_view audit = "audit"; | ||
} // namespace log_category | ||
|
||
// event log type list | ||
namespace log_type::event { | ||
static constexpr std::string_view session_start = "session_start"; | ||
static constexpr std::string_view session_end = "session_end"; | ||
} // namespace log_type::event | ||
|
||
// event log item list | ||
namespace log_item::event { | ||
static constexpr std::string_view user = "user"; | ||
static constexpr std::string_view dbname = "dbname"; | ||
static constexpr std::string_view pid = "pid"; | ||
static constexpr std::string_view remote_host = "remote_host"; | ||
static constexpr std::string_view application_name = "application_name"; | ||
static constexpr std::string_view session_id = "session_id"; | ||
} | ||
|
||
// event log level list | ||
namespace log_level::event { | ||
static constexpr int error = 30; | ||
static constexpr int info = 50; | ||
} // namespace log_level::event | ||
|
||
} // 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
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,80 @@ | ||
/* | ||
* 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 | ||
|
||
#include <sys/types.h> | ||
#include <unistd.h> | ||
|
||
#include <altimeter/configuration.h> | ||
#include <altimeter/log_item.h> | ||
#include <altimeter/logger.h> | ||
|
||
#include <tateyama/api/server/database_info.h> | ||
#include <tateyama/api/server/session_info.h> | ||
#include <tateyama/altimeter/events.h> | ||
|
||
namespace tateyama::endpoint::altimeter { | ||
// | ||
// The following two methods are created with reference to altimeter/logger/examples/altimeter/main.cpp | ||
// | ||
|
||
using namespace tateyama::altimeter; | ||
|
||
static inline void session_start(const tateyama::api::server::database_info& database_info, const tateyama::api::server::session_info& session_info) { | ||
if (::altimeter::logger::is_log_on(log_category::event, | ||
log_level::event::info)) { | ||
::altimeter::log_item log_item; | ||
log_item.category(log_category::event); | ||
log_item.type(log_type::event::session_start); | ||
log_item.level(log_level::event::info); | ||
if (auto database_name = database_info.name(); !database_name.empty()) { | ||
log_item.add(log_item::event::dbname, database_name); | ||
} | ||
log_item.add(log_item::event::pid, static_cast<pid_t>(database_info.process_id())); | ||
if (auto connection_information = session_info.connection_information(); !connection_information.empty()) { | ||
log_item.add(log_item::event::remote_host, connection_information); | ||
} | ||
if (auto application_name = session_info.application_name(); !application_name.empty()) { | ||
log_item.add(log_item::event::application_name, application_name); | ||
} | ||
log_item.add(log_item::event::session_id, static_cast<std::int64_t>(session_info.id())); | ||
::altimeter::logger::log(log_item); | ||
} | ||
} | ||
|
||
static inline void session_end(const tateyama::api::server::database_info& database_info, const tateyama::api::server::session_info& session_info) { | ||
if (::altimeter::logger::is_log_on(log_category::event, | ||
log_level::event::info)) { | ||
::altimeter::log_item log_item; | ||
log_item.category(log_category::event); | ||
log_item.type(log_type::event::session_end); | ||
log_item.level(log_level::event::info); | ||
if (auto database_name = database_info.name(); !database_name.empty()) { | ||
log_item.add(log_item::event::dbname, database_name); | ||
} | ||
log_item.add(log_item::event::pid, static_cast<pid_t>(database_info.process_id())); | ||
if (auto connection_information = session_info.connection_information(); !connection_information.empty()) { | ||
log_item.add(log_item::event::remote_host, connection_information); | ||
} | ||
if (auto application_name = session_info.application_name(); !application_name.empty()) { | ||
log_item.add(log_item::event::application_name, application_name); | ||
} | ||
log_item.add(log_item::event::session_id, static_cast<std::int64_t>(session_info.id())); | ||
::altimeter::logger::log(log_item); | ||
} | ||
} | ||
|
||
} // tateyama::endpoint::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
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