Safir SDK Core
Loading...
Searching...
No Matches
Log.h
Go to the documentation of this file.
1/******************************************************************************
2*
3* Copyright Saab AB, 2013, 2025 (http://safirsdkcore.com)
4*
5* Created by: Anders Widén
6*
7*******************************************************************************
8*
9* This file is part of Safir SDK Core.
10*
11* Safir SDK Core is free software: you can redistribute it and/or modify
12* it under the terms of version 3 of the GNU General Public License as
13* published by the Free Software Foundation.
14*
15* Safir SDK Core is distributed in the hope that it will be useful,
16* but WITHOUT ANY WARRANTY; without even the implied warranty of
17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18* GNU General Public License for more details.
19*
20* You should have received a copy of the GNU General Public License
21* along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22*
23******************************************************************************/
24#ifndef __SAFIR_LOGGING_LOG_H__
25#define __SAFIR_LOGGING_LOG_H__
26
27#include <Safir/Utilities/Internal/VisibilityHelpers.h>
28
29#ifdef logging_cpp_EXPORTS
30# define LOGGING_CPP_API SAFIR_HELPER_DLL_EXPORT
31#else
32# define LOGGING_CPP_API SAFIR_HELPER_DLL_IMPORT
33# define SAFIR_LIBRARY_NAME "logging_cpp"
34# include <Safir/Utilities/Internal/AutoLink.h>
35#endif
36#define LOGGING_CPP_LOCAL SAFIR_HELPER_DLL_LOCAL
37
38#include <string>
39
40/* For C++20 or later we add utility functions with formatting.
41 * Visual Studio does not update the __cplusplus macro unless the
42 * `/Zc:__cplusplus` compiler switch is supplied, but it always sets
43 * _MSVC_LANG to the correct value. Check both to detect C++20.
44 */
45#if ((__cplusplus >= 202002L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 202002L)))
46# if defined(__has_include)
47# if __has_include(<format>)
48# include <format>
49# endif
50# endif
51#endif
52
53namespace Safir
54{
55namespace Logging
56{
88
89
101 const std::wstring& message);
102
103 // For C++20 or later we add utility functions with formatting
104#if __cpp_lib_format
105 namespace Internal
106 {
107 //declare an internal helper function
108 LOGGING_CPP_API void LogFormattingException(const Severity severity,
109 const std::wstring& fmt,
110 const std::exception& e);
111 }
112
135 template<typename... Args>
136 void SendSystemLog(const Severity severity,
137 std::wformat_string<Args...> message,
138 Args&&... args)
139 {
140 try
141 {
142 SendSystemLog(severity, std::format(message, std::forward<Args>(args)...));
143 }
144 catch (const std::exception& e)
145 {
146 Internal::LogFormattingException(severity,std::wstring(message.get()),e);
147 }
148 }
149
156 template<typename... Args>
157 void SendEmergency(std::wformat_string<Args...> message, Args&&... args)
158 {
159 SendSystemLog(Emergency, message, std::forward<Args>(args)...);
160 }
161
168 template<typename... Args>
169 void SendAlert(std::wformat_string<Args...> message, Args&&... args)
170 {
171 SendSystemLog(Alert, message, std::forward<Args>(args)...);
172 }
173
180 template<typename... Args>
181 void SendCritical(std::wformat_string<Args...> message, Args&&... args)
182 {
183 SendSystemLog(Critical, message, std::forward<Args>(args)...);
184 }
185
192 template<typename... Args>
193 void SendError(std::wformat_string<Args...> message, Args&&... args)
194 {
195 SendSystemLog(Error, message, std::forward<Args>(args)...);
196 }
197
204 template<typename... Args>
205 void SendWarning(std::wformat_string<Args...> message, Args&&... args)
206 {
207 SendSystemLog(Warning, message, std::forward<Args>(args)...);
208 }
209
216 template<typename... Args>
217 void SendNotice(std::wformat_string<Args...> message, Args&&... args)
218 {
219 SendSystemLog(Notice, message, std::forward<Args>(args)...);
220 }
221
228 template<typename... Args>
229 void SendInformational(std::wformat_string<Args...> message, Args&&... args)
230 {
231 SendSystemLog(Informational, message, std::forward<Args>(args)...);
232 }
233
240 template<typename... Args>
241 void SendDebug(std::wformat_string<Args...> message, Args&&... args)
242 {
243 SendSystemLog(Debug, message, std::forward<Args>(args)...);
244 }
245
246#endif
247
248
249}
250}
251
252
253#endif
#define LOGGING_CPP_API
Definition Log.h:32
This namespace contains all the functionality and definitions of the SAFIR SDK.
Definition Backdoor.h:31
Definition Log.h:56
SAFIR_HELPER_DLL_IMPORT void SendSystemLog(const Severity severity, const std::wstring &message)
Send log messages to the system logging mechanism.
Severity
Severity level according to RFC 3164.
Definition Log.h:63
@ Notice
RFC 3164 Description: Normal but significant condition.
Definition Log.h:80
@ Emergency
RFC 3164 Description: System is unusable.
Definition Log.h:65
@ Debug
RFC 3164 Description: Debug-level messages.
Definition Log.h:86
@ Critical
RFC 3164 Description: Critical conditions.
Definition Log.h:71
@ Error
RFC 3164 Description: Error conditions.
Definition Log.h:74
@ Warning
RFC 3164 Description: Warning conditions.
Definition Log.h:77
@ Alert
RFC 3164 Description: Action must be taken immediately.
Definition Log.h:68
@ Informational
RFC 3164 Description: Informational messages.
Definition Log.h:83