xref: /aosp_15_r20/external/ComputeLibrary/arm_compute/core/utils/logging/LoggerRegistry.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2017-2019 Arm Limited.
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
54      * @param[in] log_level Logger's log level. Defaults to INFO
55      * @param[in] printers  Printers to attach to the system loggers. Defaults with a @ref StdPrinter.
56      */
57     void create_logger(const std::string &name, LogLevel log_level = LogLevel::INFO,
58                        const std::vector<std::shared_ptr<Printer>> &printers = { std::make_shared<StdPrinter>() });
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      *
73      * @param[in] log_level (Optional) Logger's log level. Defaults to INFO
74      * @param[in] printers  (Optional) Printers to attach to the system loggers. Defaults with a @ref StdPrinter.
75      */
76     void create_reserved_loggers(LogLevel                                     log_level = LogLevel::INFO,
77                                  const std::vector<std::shared_ptr<Printer>> &printers  = { std::make_shared<StdPrinter>() });
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 */
91