blob: 066a42ff4fac63b9a5a7f30d22bfc0c28f1787eb [file] [log] [blame]
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +01001/*
Alex Gildayc357c472018-03-21 13:54:09 +00002 * Copyright (c) 2017-2018 ARM Limited.
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +01003 *
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
36namespace arm_compute
37{
38namespace logging
39{
40/** Registry class holding all the instantiated loggers */
41class LoggerRegistry final
42{
43public:
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 Gildayc357c472018-03-21 13:54:09 +000054 * @param[in] log_level Logger's log level. Defaults to INFO
Georgios Pinitas3faea252017-10-30 14:13:50 +000055 * @param[in] printers Printers to attach to the system loggers. Defaults with a @ref StdPrinter.
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010056 */
Georgios Pinitas3faea252017-10-30 14:13:50 +000057 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 Pinitas7d3d1b92017-10-12 17:34:20 +010059 /** 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 Gildayc357c472018-03-21 13:54:09 +000073 * @param[in] log_level (Optional) Logger's log level. Defaults to INFO
Georgios Pinitas3faea252017-10-30 14:13:50 +000074 * @param[in] printers (Optional) Printers to attach to the system loggers. Defaults with a @ref StdPrinter.
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010075 */
Georgios Pinitas3faea252017-10-30 14:13:50 +000076 void create_reserved_loggers(LogLevel log_level = LogLevel::INFO,
77 std::vector<std::shared_ptr<Printer>> printers = { std::make_shared<StdPrinter>() });
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010078
79private:
80 /** Default constructor */
81 LoggerRegistry();
82
83private:
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__ */