Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
logging.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18// logging infrastructure for Realm
19
20#ifndef REALM_LOGGING_H
21#define REALM_LOGGING_H
22
23#include "realm/realm_config.h"
24#include "realm/utils.h"
25
26#include <stdarg.h>
27#include <vector>
28#include <string>
29#include <sstream>
30
31namespace Realm {
32 // this can be set at compile time to eliminate instructions for some/all logging
33#ifndef REALM_LOGGING_MIN_LEVEL
34 // old define name
35#ifdef COMPILE_TIME_MIN_LEVEL
36#define REALM_LOGGING_MIN_LEVEL COMPILE_TIME_MIN_LEVEL
37#else
38#define REALM_LOGGING_MIN_LEVEL LEVEL_DEBUG
39#endif
40#endif
41 namespace Config {
42 // output of logs, the default value is "stdout"
43 // it can be set to a filename, stdout or stderr
44 extern std::string logname;
45 }; // namespace Config
46
47 class LoggerMessage;
48 class LoggerConfig;
49 class LoggerOutputStream;
50 struct DelayedMessage;
51
53 public:
54 Logger(const std::string &_name);
55 ~Logger(void);
56
58 {
59 LEVEL_SPEW, // LOTS of stuff
66 LEVEL_NONE, // if you really want to turn EVERYTHING off
67 };
68
69 static void configure_from_cmdline(std::vector<std::string> &cmdline);
71 static void set_logger_output(const std::string &name, LoggerOutputStream *s);
72
73 const std::string &get_name(void) const;
75
76 // boolean tests to see if the specified logging level is active - lets
77 // complicated logging messages be put inside conditionals
78 bool want_spew(void) const;
79 bool want_debug(void) const;
80 bool want_info(void) const;
81 bool want_print(void) const;
82 bool want_warning(void) const;
83 bool want_error(void) const;
84 bool want_fatal(void) const;
85
93
94 // use this only if you want a dynamic level for some reason
96
97 // old printf-style interface
98 REALM_ATTR_PRINTF_FORMAT(void spew(const char *fmt, ...), 2, 3);
99 REALM_ATTR_PRINTF_FORMAT(void debug(const char *fmt, ...), 2, 3);
100 REALM_ATTR_PRINTF_FORMAT(void info(const char *fmt, ...), 2, 3);
101 REALM_ATTR_PRINTF_FORMAT(void print(const char *fmt, ...), 2, 3);
102 REALM_ATTR_PRINTF_FORMAT(void warning(const char *fmt, ...), 2, 3);
103 REALM_ATTR_PRINTF_FORMAT(void error(const char *fmt, ...), 2, 3);
104 REALM_ATTR_PRINTF_FORMAT(void fatal(const char *fmt, ...), 2, 3);
105
106 protected:
107 friend class LoggerMessage;
108
110 void log_msg(LoggingLevel level, const char *msgdata, size_t msglen);
111
112 friend class LoggerConfig;
113
115 void add_stream(LoggerOutputStream *s, LoggingLevel min_level, bool delete_when_done,
116 bool flush_each_write);
118 void configure_done(void);
119
126
127 std::string name;
128 std::vector<LogStream> streams;
129 LoggingLevel log_level; // the min level of any stream
131 // remember messages that are emitted before we're configured
132 DelayedMessage *delayed_message_head;
133 DelayedMessage **delayed_message_tail;
134 };
135
137 protected:
138 // can only be created by a Logger
139 friend class Logger;
140
141 LoggerMessage(void); // default constructor makes an inactive message
142 LoggerMessage(Logger *_logger, bool _active, Logger::LoggingLevel _level);
143
144 public:
147
148 template <typename T>
149 LoggerMessage &operator<<(const T &val);
150
151 // vprintf-style
152 LoggerMessage &vprintf(const char *fmt, va_list ap);
153
154 bool is_active(void) const;
155
156 void deactivate(void);
157
158 std::ostream &get_stream(void);
159
160 protected:
162 bool active;
164 // contain messages shorter than 160 characters entirely inline
167 };
168
170 public:
172
173 virtual void log_msg(Logger::LoggingLevel level, const char *name,
174 const char *msgdata, size_t msglen) = 0;
175 virtual void flush() = 0;
176 };
177
178}; // namespace Realm
179
180#include "realm/logging.inl"
181
182#endif
Definition utils.h:176
Definition logging.h:136
Logger * logger
Definition logging.h:161
LoggerMessage & vprintf(const char *fmt, va_list ap)
std::ostream & get_stream(void)
DeferredConstructor< std::ostream > stream
Definition logging.h:166
LoggerMessage(const LoggerMessage &to_copy)
bool active
Definition logging.h:162
LoggerMessage & operator<<(const T &val)
bool is_active(void) const
LoggerMessage(Logger *_logger, bool _active, Logger::LoggingLevel _level)
Logger::LoggingLevel level
Definition logging.h:163
DeferredConstructor< shortstringbuf< 160, 256 > > buffer
Definition logging.h:165
Definition logging.h:169
virtual void log_msg(Logger::LoggingLevel level, const char *name, const char *msgdata, size_t msglen)=0
virtual ~LoggerOutputStream()
Definition logging.h:171
virtual void flush()=0
Definition logging.h:52
bool want_print(void) const
LoggerMessage warning(void)
static void configure_from_cmdline(std::vector< std::string > &cmdline)
static void set_logger_output(const std::string &name, LoggerOutputStream *s)
std::string name
Definition logging.h:127
const std::string & get_name(void) const
REALM_ATTR_PRINTF_FORMAT(void debug(const char *fmt,...), 2, 3)
LoggerMessage debug(void)
LoggingLevel log_level
Definition logging.h:129
bool configured
Definition logging.h:130
bool want_error(void) const
std::vector< LogStream > streams
Definition logging.h:128
REALM_ATTR_PRINTF_FORMAT(void warning(const char *fmt,...), 2, 3)
LoggerMessage spew(void)
bool want_info(void) const
REALM_INTERNAL_API_EXTERNAL_LINKAGE void log_msg(LoggingLevel level, const char *msgdata, size_t msglen)
LoggerMessage info(void)
static void set_default_output(LoggerOutputStream *s)
bool want_fatal(void) const
REALM_INTERNAL_API void configure_done(void)
LoggingLevel
Definition logging.h:58
@ LEVEL_NONE
Definition logging.h:66
@ LEVEL_PRINT
Definition logging.h:62
@ LEVEL_SPEW
Definition logging.h:59
@ LEVEL_WARNING
Definition logging.h:63
@ LEVEL_DEBUG
Definition logging.h:60
@ LEVEL_FATAL
Definition logging.h:65
@ LEVEL_ERROR
Definition logging.h:64
@ LEVEL_INFO
Definition logging.h:61
LoggerMessage fatal(void)
LoggerMessage error(void)
REALM_INTERNAL_API void add_stream(LoggerOutputStream *s, LoggingLevel min_level, bool delete_when_done, bool flush_each_write)
bool want_spew(void) const
Logger(const std::string &_name)
bool want_warning(void) const
REALM_ATTR_PRINTF_FORMAT(void error(const char *fmt,...), 2, 3)
REALM_ATTR_PRINTF_FORMAT(void info(const char *fmt,...), 2, 3)
REALM_ATTR_PRINTF_FORMAT(void spew(const char *fmt,...), 2, 3)
LoggerMessage print(void)
bool want_debug(void) const
LoggingLevel get_level(void) const
REALM_ATTR_PRINTF_FORMAT(void print(const char *fmt,...), 2, 3)
LoggerMessage newmsg(LoggingLevel level)
DelayedMessage * delayed_message_head
Definition logging.h:132
DelayedMessage ** delayed_message_tail
Definition logging.h:133
REALM_ATTR_PRINTF_FORMAT(void fatal(const char *fmt,...), 2, 3)
#define REALM_INTERNAL_API_EXTERNAL_LINKAGE
Definition compiler_support.h:218
#define REALM_INTERNAL_API
Definition compiler_support.h:219
#define REALM_PUBLIC_API
Definition compiler_support.h:217
std::string logname
Definition activemsg.h:38
Definition logging.h:120
bool delete_when_done
Definition logging.h:123
LoggerOutputStream * s
Definition logging.h:121
bool flush_each_write
Definition logging.h:124
LoggingLevel min_level
Definition logging.h:122