Georgios Pinitas | 7d3d1b9 | 2017-10-12 17:34:20 +0100 | [diff] [blame] | 1 | /* |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Georgios Pinitas | 7d3d1b9 | 2017-10-12 17:34:20 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef __ARM_COMPUTE_LOGGING_LOGGER_REGISTRY_H__ |
| 25 | #define __ARM_COMPUTE_LOGGING_LOGGER_REGISTRY_H__ |
| 26 | |
| 27 | #include "arm_compute/core/utils/logging/Logger.h" |
| 28 | #include "arm_compute/core/utils/logging/Printers.h" |
| 29 | #include "arm_compute/core/utils/logging/Types.h" |
| 30 | #include "support/Mutex.h" |
| 31 | |
| 32 | #include <memory> |
| 33 | #include <set> |
| 34 | #include <unordered_map> |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace logging |
| 39 | { |
| 40 | /** Registry class holding all the instantiated loggers */ |
| 41 | class LoggerRegistry final |
| 42 | { |
| 43 | public: |
| 44 | /** Gets registry instance |
| 45 | * |
| 46 | * @return Logger registry instance |
| 47 | */ |
| 48 | static LoggerRegistry &get(); |
| 49 | /** Creates a logger |
| 50 | * |
| 51 | * @note Some names are reserved e.g. [CORE, RUNTIME, GRAPH] |
| 52 | * |
| 53 | * @param[in] name Logger's name |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 54 | * @param[in] log_level Logger's log level. Defaults to INFO |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 55 | * @param[in] printers Printers to attach to the system loggers. Defaults with a @ref StdPrinter. |
Georgios Pinitas | 7d3d1b9 | 2017-10-12 17:34:20 +0100 | [diff] [blame] | 56 | */ |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 57 | void create_logger(const std::string &name, LogLevel log_level = LogLevel::INFO, |
| 58 | std::vector<std::shared_ptr<Printer>> printers = { std::make_shared<StdPrinter>() }); |
Georgios Pinitas | 7d3d1b9 | 2017-10-12 17:34:20 +0100 | [diff] [blame] | 59 | /** Remove a logger |
| 60 | * |
| 61 | * @param name Logger's name |
| 62 | */ |
| 63 | void remove_logger(const std::string &name); |
| 64 | /** Returns a logger instance |
| 65 | * |
| 66 | * @param[in] name Logger to return |
| 67 | * |
| 68 | * @return Logger |
| 69 | */ |
| 70 | std::shared_ptr<Logger> logger(const std::string &name); |
| 71 | /** Creates reserved library loggers |
| 72 | * |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 73 | * @param[in] log_level (Optional) Logger's log level. Defaults to INFO |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 74 | * @param[in] printers (Optional) Printers to attach to the system loggers. Defaults with a @ref StdPrinter. |
Georgios Pinitas | 7d3d1b9 | 2017-10-12 17:34:20 +0100 | [diff] [blame] | 75 | */ |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 76 | void create_reserved_loggers(LogLevel log_level = LogLevel::INFO, |
| 77 | std::vector<std::shared_ptr<Printer>> printers = { std::make_shared<StdPrinter>() }); |
Georgios Pinitas | 7d3d1b9 | 2017-10-12 17:34:20 +0100 | [diff] [blame] | 78 | |
| 79 | private: |
| 80 | /** Default constructor */ |
| 81 | LoggerRegistry(); |
| 82 | |
| 83 | private: |
| 84 | arm_compute::Mutex _mtx; |
| 85 | std::unordered_map<std::string, std::shared_ptr<Logger>> _loggers; |
| 86 | static std::set<std::string> _reserved_loggers; |
| 87 | }; |
| 88 | } // namespace logging |
| 89 | } // namespace arm_compute |
| 90 | #endif /* __ARM_COMPUTE_LOGGING_LOGGER_REGISTRY_H__ */ |