ArcGIS Procedural Runtime  3.2.10650
Log.h
1 /*
2  COPYRIGHT (c) 2012-2024 Esri R&D Center Zurich
3  TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
4  Unpublished material - all rights reserved under the
5  Copyright Laws of the United States and applicable international
6  laws, treaties, and conventions.
7 
8  For additional information, contact:
9  Environmental Systems Research Institute, Inc.
10  Attn: Contracts and Legal Services Department
11  380 New York Street
12  Redlands, California, 92373
13  USA
14 
15  email: contracts@esri.com
16 */
17 
18 #pragma once
19 
20 #include "prtx/prtx.h"
21 #include "prtx/Types.h"
22 #include "prtx/URI.h"
23 #include "prtx/OpaquePtr.h"
24 
25 #include "prt/LogLevel.h"
26 #include "prt/LogHandler.h"
27 #include "prt/Status.h"
28 
29 #include <exception>
30 #include <ostream>
31 #include <string>
32 #include <vector>
33 
34 #ifndef PRTX_LOG_ENABLED
35 # define PRTX_LOG_ENABLED 1 // enable prtx logger by default
36 #endif
37 
38 #ifndef PRTX_LOG_ENFORCE_TRACING
39 # define PRTX_LOG_ENFORCE_TRACING 0 // set to 1 if you want tracing even in PRT_CC_OPT or PRT_CC_OPT_SYM
40 #endif
41 
42 #if (PRTX_LOG_ENFORCE_TRACING == 1) && defined(PRT_BC_REL)
43 # error "enforcing tracing in release build configuration is not allowed"
44 #endif
45 
46 
47 namespace prtx {
48 
49 
50 class BoundingBox;
51 class Reports;
52 typedef std::shared_ptr<Reports> ReportsPtr;
53 
89 class PRTX_EXPORTS_API LogFormatter {
90 public:
95  explicit LogFormatter(prt::LogLevel l);
96 
100  LogFormatter(prt::LogLevel l, const std::string& s);
101  LogFormatter(prt::LogLevel l, const std::wstring& s);
102 
107  LogFormatter(prt::LogLevel l, const std::string& s, const std::string& p);
108  LogFormatter(prt::LogLevel l, const char* s, const char* p = 0);
109  LogFormatter(prt::LogLevel l, const std::wstring& s, const std::wstring& p);
110  LogFormatter(prt::LogLevel l, const std::wstring& s, const std::string& p);
111  LogFormatter(prt::LogLevel l, const wchar_t* s, const wchar_t* p = 0);
112 
116  LogFormatter(prt::LogLevel l, const std::exception& e);
117 
121  LogFormatter(prt::LogLevel l, const std::string& s, const std::exception& e);
122 
123  LogFormatter& operator%(float x);
124  LogFormatter& operator%(double x);
125 
126 #ifndef __linux__
127  LogFormatter& operator%(long int x);
128 #ifndef _MSC_VER
129  LogFormatter& operator%(std::size_t x);
130 #endif
131 #endif
132 
133  LogFormatter& operator%(uint8_t x);
134  LogFormatter& operator%(uint16_t x);
135  LogFormatter& operator%(uint32_t x);
136  LogFormatter& operator%(uint64_t x);
137 
138  LogFormatter& operator%(int8_t x);
139  LogFormatter& operator%(int16_t x);
140  LogFormatter& operator%(int32_t x);
141  LogFormatter& operator%(int64_t x);
142 
143  LogFormatter& operator%(const char* x);
144  LogFormatter& operator%(const std::string& x);
145  LogFormatter& operator%(const StringVector& x);
146 
147  LogFormatter& operator%(const wchar_t* x);
148  LogFormatter& operator%(const std::wstring& x);
149  LogFormatter& operator%(const WStringVector& x);
150 
151  LogFormatter& operator%(const prt::Status& x);
152  LogFormatter& operator%(const prt::LogLevel& x);
153  LogFormatter& operator%(const URIPtr& x);
154  LogFormatter& operator%(const BoundingBox& x);
155  LogFormatter& operator%(const DoubleVector& x);
156  LogFormatter& operator%(const ReportsPtr& r);
157 
158  LogFormatter& operator%(const std::vector<uint32_t>& v);
159  LogFormatter& log(uint32_t const* array, size_t count);
160 
161  LogFormatter() = delete;
162  LogFormatter(const LogFormatter&) = delete;
163  LogFormatter(LogFormatter&&) = delete;
164  LogFormatter& operator=(const LogFormatter&) = delete;
165  LogFormatter& operator=(LogFormatter&&) = delete;
166  virtual ~LogFormatter();
167 
168 protected:
169  std::wstring getMessage() const;
170 
171 private:
172  BEGIN_SUPPRESS_EXPORT_WARNINGS
173  class LogFormatterImpl;
175  END_SUPPRESS_EXPORT_WARNINGS
176 };
177 
178 
182 template<bool E, prt::LogLevel L, typename LT>
183 class LogFwd final {
184 public:
185  template<typename... ARGS>
186  LogFwd(ARGS&&...) { }
187 
188  template<typename T>
189  LogFwd& operator%(T&&) { return *this; }
190 };
191 
192 
196 template<prt::LogLevel L, typename LT>
197 class LogFwd<true, L, LT> final : protected LT {
198 public:
199  template<typename... ARGS>
200  LogFwd(ARGS&&... args) : LT(L, args...) { }
201 
202  template<typename T>
203  LogFwd& operator%(T&& t) { LT::operator%(t); return *this; }
204 };
205 
206 #if (defined(PRT_CC_DBG) && (PRT_CC_DBG == 1))
207 constexpr bool isDBG = true;
208 #else
209 constexpr bool isDBG = false;
210 #endif
211 
212 template<prt::LogLevel L>
213 constexpr bool IsLogEnabled = (PRTX_LOG_ENABLED == 1) && ((L != prt::LOG_TRACE) || ((L == prt::LOG_TRACE) && isDBG) || (PRTX_LOG_ENFORCE_TRACING == 1));
214 
215 template<prt::LogLevel L>
217 
218 
219 } // namespace prtx
220 
221 
Definition: BoundingBox.h:38
std::vector< double > DoubleVector
vector of double
Definition: Types.h:32
Definition: Log.h:183
LogLevel
Definition: LogLevel.h:29
Internal call tracing. This log level is unused in release builds of the runtime but may be used by c...
Definition: LogLevel.h:30
std::vector< std::string > StringVector
vector of std::string
Definition: Types.h:34
The Procedural Runtime eXtension namespace. The prtx namespace contains the tools to extend the Proce...
Definition: AnnotationBuilder.h:35
std::shared_ptr< URI > URIPtr
shared pointer implementation of prtx::URI
Definition: URI.h:37
Status
Definition: Status.h:31
std::vector< std::wstring > WStringVector
vector of std::wstring
Definition: Types.h:35
Definition: Log.h:89