VR-Engage  2.3
Loading...
Searching...
No Matches
logger.h
Go to the documentation of this file.
1/*********************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*********************************************************************************/
5
6#pragma once
7
8//! \file logger.h
9//! \brief Provides logging functionality with various severity levels and channels
10
11#include "vreUtil/export.h"
12
13#include <vlutil/vlPrint.h>
14
15//! \brief Macro to extract just the filename from a full path
16//!
17//! This macro extracts the filename from the full path in __FILE__
18//! Returns the filename without the directory path
19#define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
20
21//! \brief Generates a timestamp string for log messages
22//!
23//! \return A formatted timestamp string for use in log messages
24std::string UTIL_DLL logTimestamp();
25
26//! \brief Writes a timestamp string into a caller-provided buffer.
27//!
28//! Prefer this overload in performance-sensitive paths to avoid heap allocation.
29//! The buffer must be at least 13 bytes to hold "HH:MM:SS.mmm" plus a null terminator.
30//!
31//! \param buf Buffer to write the timestamp into.
32//! \param bufSize Size of buf in bytes.
33UTIL_DLL void logTimestamp(char* buf, size_t bufSize);
34
35//! \brief Logs a fatal error message
36//!
37//! \param channel The logging channel/category to use
38//! \param function The function name where the log originated
39//! \return An output stream to write the message to
40UTIL_DLL DtOutputStream& DtVreFatalStream(const std::string& channel, const std::string& function);
41
42//! \brief Logs a warning message
43//!
44//! \param channel The logging channel/category to use
45//! \param function The function name where the log originated
46//! \return An output stream to write the message to
47UTIL_DLL DtOutputStream& DtVreWarnStream(const std::string& channel, const std::string& function);
48
49//! \brief Logs an informational message
50//!
51//! \param channel The logging channel/category to use
52//! \param function The function name where the log originated
53//! \return An output stream to write the message to
54UTIL_DLL DtOutputStream& DtVreInfoStream(const std::string& channel, const std::string& function);
55
56//! \brief Logs a verbose message (more detailed than info)
57//!
58//! \param channel The logging channel/category to use
59//! \param function The function name where the log originated
60//! \return An output stream to write the message to
61UTIL_DLL DtOutputStream& DtVreVerboseStream(const std::string& channel, const std::string& function);
62
63//! \brief Logs a debug message
64//!
65//! \param channel The logging channel/category to use
66//! \param function The function name where the log originated
67//! \return An output stream to write the message to
68UTIL_DLL DtOutputStream& DtVreDebugStream(const std::string& channel, const std::string& function);
69
70//! \brief Logs a fatal message using printf-style formatting.
71//!
72//! Prefer this over LOG_FATAL in performance-sensitive code paths.
73//!
74//! \param channel The logging channel/category to use.
75//! \param function The function name where the log originated.
76//! \param format A printf-style format string.
77UTIL_DLL void DtVreFatal(const std::string& channel, const std::string& function, const char* format, ...);
78
79//! \brief Logs a warning message using printf-style formatting.
80//!
81//! Prefer this over LOG_WARN in performance-sensitive code paths.
82//!
83//! \param channel The logging channel/category to use.
84//! \param function The function name where the log originated.
85//! \param format A printf-style format string.
86UTIL_DLL void DtVreWarn(const std::string& channel, const std::string& function, const char* format, ...);
87
88//! \brief Logs an informational message using printf-style formatting.
89//!
90//! Prefer this over LOG_INFO in performance-sensitive code paths.
91//!
92//! \param channel The logging channel/category to use.
93//! \param function The function name where the log originated.
94//! \param format A printf-style format string.
95UTIL_DLL void DtVreInfo(const std::string& channel, const std::string& function, const char* format, ...);
96
97//! \brief Logs a verbose message using printf-style formatting.
98//!
99//! Prefer this over LOG_VERBOSE in performance-sensitive code paths.
100//!
101//! \param channel The logging channel/category to use.
102//! \param function The function name where the log originated.
103//! \param format A printf-style format string.
104UTIL_DLL void DtVreVerbose(const std::string& channel, const std::string& function, const char* format, ...);
105
106//! \brief Logs a debug message using printf-style formatting.
107//!
108//! Prefer this over LOG_DEBUG in performance-sensitive code paths.
109//!
110//! \param channel The logging channel/category to use.
111//! \param function The function name where the log originated.
112//! \param format A printf-style format string.
113UTIL_DLL void DtVreDebug(const std::string& channel, const std::string& function, const char* format, ...);
114
115//! \brief Macro to log a fatal message to log files
116//!
117//! \param channel The logging channel/category to use
118#define LOG_FATAL_STREAM(channel) DtVreFatalStream(channel, __FUNCTION__)
119
120//! \brief Macro to log a warning message to log files
121//!
122//! \param channel The logging channel/category to use
123#define LOG_WARN_STREAM(channel) DtVreWarnStream(channel, __FUNCTION__)
124
125//! \brief Macro to log an informational message to log files
126//!
127//! \param channel The logging channel/category to use
128#define LOG_INFO_STREAM(channel) DtVreInfoStream(channel, __FUNCTION__)
129
130//! \brief Macro to log a verbose message to log files
131//!
132//! \param channel The logging channel/category to use
133#define LOG_VERBOSE_STREAM(channel) DtVreVerboseStream(channel, __FUNCTION__)
134
135//! \brief Macro to log a debug message to log files
136//!
137//! \param channel The logging channel/category to use
138#define LOG_DEBUG_STREAM(channel) DtVreDebugStream(channel, __FUNCTION__)
139
140//! \brief Macro to log a fatal message using printf-style formatting.
141//!
142//! \param channel The logging channel/category to use.
143//! \param format A printf-style format string.
144#define LOG_FATAL(channel, format, ...) DtVreFatal(channel, __FUNCTION__, format, ##__VA_ARGS__)
145
146//! \brief Macro to log a warning message using printf-style formatting.
147//!
148//! \param channel The logging channel/category to use.
149//! \param format A printf-style format string.
150#define LOG_WARN(channel, format, ...) DtVreWarn(channel, __FUNCTION__, format, ##__VA_ARGS__)
151
152//! \brief Macro to log an informational message using printf-style formatting.
153//!
154//! \param channel The logging channel/category to use.
155//! \param format A printf-style format string.
156#define LOG_INFO(channel, format, ...) DtVreInfo(channel, __FUNCTION__, format, ##__VA_ARGS__)
157
158//! \brief Macro to log a verbose message using printf-style formatting.
159//!
160//! \param channel The logging channel/category to use.
161//! \param format A printf-style format string.
162#define LOG_VERBOSE(channel, format, ...) DtVreVerbose(channel, __FUNCTION__, format, ##__VA_ARGS__)
163
164//! \brief Macro to log a debug message using printf-style formatting.
165//!
166//! \param channel The logging channel/category to use.
167//! \param format A printf-style format string.
168#define LOG_DEBUG(channel, format, ...) DtVreDebug(channel, __FUNCTION__, format, ##__VA_ARGS__)
169
170//! \brief Macro to log a fatal message to an entity's object console
171//!
172//! \param channel The logging channel/category to use
173#define OBJCON_FATAL(channel) \
174 entity()->objectConsoleError() << "FATAL[" << channel << "] " << logTimestamp() << " " << __FUNCTION__ << ": "
175
176//! \brief Macro to log a warning message to an entity's object console
177//!
178//! \param channel The logging channel/category to use
179#define OBJCON_WARN(channel) \
180 entity()->objectConsoleWarn() << "WARN[" << channel << "] " << logTimestamp() << " " << __FUNCTION__ << ": "
181
182//! \brief Macro to log an informational message to an entity's object console
183//!
184//! \param channel The logging channel/category to use
185#define OBJCON_INFO(channel) \
186 entity()->objectConsoleInfo() << "INFO[" << channel << "] " << logTimestamp() << " " << __FUNCTION__ << ": "
187
188//! \brief Macro to log a verbose message to an entity's object console
189//!
190//! \param channel The logging channel/category to use
191#define OBJCON_VERBOSE(channel) \
192 entity()->objectConsoleVerbose() << "VERBOSE[" << channel << "] " << logTimestamp() << " " << __FUNCTION__ << ": "
193
194//! \brief Macro to log a debug message to an entity's object console
195//!
196//! \param channel The logging channel/category to use
197#define OBJCON_DEBUG(channel) \
198 entity()->objectConsoleDebug() << "DEBUG[" << channel << "] " << logTimestamp() << " " << __FUNCTION__ << ": "
Defines export macros for the VREngage Utility library.
#define UTIL_DLL
Export/import macro for non-Windows platforms.
Definition export.h:39
std::string UTIL_DLL logTimestamp()
Generates a timestamp string for log messages.
UTIL_DLL void DtVreFatal(const std::string &channel, const std::string &function, const char *format,...)
Logs a fatal message using printf-style formatting.
UTIL_DLL DtOutputStream & DtVreDebugStream(const std::string &channel, const std::string &function)
Logs a debug message.
UTIL_DLL void DtVreVerbose(const std::string &channel, const std::string &function, const char *format,...)
Logs a verbose message using printf-style formatting.
UTIL_DLL DtOutputStream & DtVreWarnStream(const std::string &channel, const std::string &function)
Logs a warning message.
UTIL_DLL DtOutputStream & DtVreVerboseStream(const std::string &channel, const std::string &function)
Logs a verbose message (more detailed than info)
UTIL_DLL DtOutputStream & DtVreInfoStream(const std::string &channel, const std::string &function)
Logs an informational message.
UTIL_DLL DtOutputStream & DtVreFatalStream(const std::string &channel, const std::string &function)
Logs a fatal error message.
UTIL_DLL void DtVreWarn(const std::string &channel, const std::string &function, const char *format,...)
Logs a warning message using printf-style formatting.
UTIL_DLL void DtVreInfo(const std::string &channel, const std::string &function, const char *format,...)
Logs an informational message using printf-style formatting.
UTIL_DLL void DtVreDebug(const std::string &channel, const std::string &function, const char *format,...)
Logs a debug message using printf-style formatting.