Line data Source code
1 : /* 2 : Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain 3 : Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany 4 : 5 : This software was partially supported by the 6 : EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu). 7 : 8 : This software was partially supported by the 9 : ADA-FS project under the SPPEXA project funded by the DFG. 10 : 11 : This file is part of GekkoFS. 12 : 13 : GekkoFS is free software: you can redistribute it and/or modify 14 : it under the terms of the GNU General Public License as published by 15 : the Free Software Foundation, either version 3 of the License, or 16 : (at your option) any later version. 17 : 18 : GekkoFS is distributed in the hope that it will be useful, 19 : but WITHOUT ANY WARRANTY; without even the implied warranty of 20 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 : GNU General Public License for more details. 22 : 23 : You should have received a copy of the GNU General Public License 24 : along with GekkoFS. If not, see <https://www.gnu.org/licenses/>. 25 : 26 : SPDX-License-Identifier: GPL-3.0-or-later 27 : */ 28 : /** 29 : * @brief Declaration for GekkoFS data module object that is run once per daemon 30 : * instance. 31 : */ 32 : 33 : #ifndef GEKKOFS_DAEMON_DATA_LOGGING_HPP 34 : #define GEKKOFS_DAEMON_DATA_LOGGING_HPP 35 : 36 : #include <spdlog/spdlog.h> 37 : 38 : namespace gkfs::data { 39 : 40 : /** 41 : * @brief The data module class providing the data backend for the daemon as a 42 : * singleton. 43 : */ 44 : class DataModule { 45 : 46 : private: 47 : DataModule() = default; 48 : 49 : std::shared_ptr<spdlog::logger> log_; ///< Logging instance for data backend 50 : 51 : public: 52 : static constexpr const char* LOGGER_NAME = "DataModule"; 53 : 54 : static DataModule* 55 132 : getInstance() { 56 132 : static DataModule instance; 57 132 : return &instance; 58 : } 59 : 60 : DataModule(DataModule const&) = delete; 61 : 62 : void 63 : operator=(DataModule const&) = delete; 64 : 65 : /** 66 : * @brief Returns the data module log handle. 67 : * @return Pointer to the spdlog instance 68 : */ 69 : [[nodiscard]] const std::shared_ptr<spdlog::logger>& 70 : log() const; 71 : 72 : /** 73 : * @brief Attaches a logging instance to the data module. 74 : * @param log spdlog shared pointer instance 75 : */ 76 : void 77 : log(const std::shared_ptr<spdlog::logger>& log); 78 : }; 79 : 80 : #define GKFS_DATA_MOD \ 81 : (static_cast<gkfs::data::DataModule*>( \ 82 : gkfs::data::DataModule::getInstance())) ///< macro to access the 83 : ///< DataModule singleton 84 : ///< across the daemon 85 : 86 : } // namespace gkfs::data 87 : 88 : #endif // GEKKOFS_DAEMON_DATA_LOGGING_HPP