scc 2025.09
SystemC components library
instance_logger.h
1/*******************************************************************************
2 * Copyright (C) 2025 MINRES Technologies GmbH
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 *******************************************************************************/
32
33#ifndef _ISS_LOGGER_H_
34#define _ISS_LOGGER_H_
35
36#include "delegate.h"
37#include "logging.h"
38
39namespace util {
40
42 using delegate_fn = void(logging::log_level, std::string const&, std::string const&, unsigned, char const*);
45};
46
52template <typename CATEGORY> class InstanceLogger {
53public:
54 InstanceLogger() = default;
55
56 ~InstanceLogger() = default;
57
58 InstanceLogger(const InstanceLogger&) = delete;
59
60 InstanceLogger& operator=(const InstanceLogger&) = delete;
61
62 void set_log_level(logging::log_level l) {
63 if(logger) {
64 logger->level = l;
65 } else {
66 ::logging ::Log<::logging ::Output2FILE<CATEGORY>>::set_reporting_level(l);
67 }
68 }
69 logging::log_level get_log_level() {
70 if(logger) {
71 return logger->level;
72 } else {
73 return ::logging ::Log<::logging ::Output2FILE<CATEGORY>>::get_reporting_level();
74 }
75 }
76 void log(logging::log_level level, const std::string& message, unsigned line, char const* file) {
77 if(logger) {
78 logger->log(level, CATEGORY::name, message, line, file);
79 } else {
80 if(level <= _LOGGER(CATEGORY)::get_reporting_level() && _LOG_OUTPUT(CATEGORY)::stream())
81 ::logging::Log<::logging::Output2FILE<CATEGORY>>().get(level, CATEGORY::name) << message;
82 }
83 }
84
85 void set_logger(LoggerDelegate& logger) { this->logger = &logger; }
86
87private:
88 LoggerDelegate* logger;
89};
90} // namespace util
91
92#define ILOG(LOGGER, LEVEL, MSG) \
93 if(LEVEL <= this->LOGGER.get_log_level()) { \
94 this->LOGGER.log(LEVEL, MSG, __LINE__, __FILE__); \
95 }
96#endif // _ISS_LOGGER_H_
log_level
enum defining the log levels
Definition logging.h:53
SCC common utilities.
Definition bit_field.h:30