OnixS C++ Eurex T7 Market and Reference Data Interface (EMDI, RDI, EOBI) Handlers  8.1.0
API documentation
HandlerLogger.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*
4 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
5 *
6 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
7 * and international copyright treaties.
8 *
9 * Access to and use of the software is governed by the terms of the applicable ONIXS Software
10 * Services Agreement (the Agreement) and Customer end user license agreements granting
11 * a non-assignable, non-transferable and non-exclusive license to use the software
12 * for it's own data processing purposes under the terms defined in the Agreement.
13 *
14 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
15 * of this source code or associated reference material to any other location for further reproduction
16 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
17 *
18 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
19 * the terms of the Agreement is a violation of copyright law.
20 */
21 
23 
24 #include <logging/FileOutput.h>
25 
26 #include <OnixS/HandlerCore/HandlerLogger.h>
27 
28 
29 //////////////////////////////////////////////////////////////////////////
30 // Source info defines
31 
32 #define DIRECTEDGE_SOURCE_INFO ::OnixS::Logging::SourceInfo(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
33 #define DIRECTEDGE_SOURCE_FUNC ::OnixS::Logging::SourceInfo(nullptr, 0, BOOST_CURRENT_FUNCTION)
34 #define DIRECTEDGE_SOURCE_LINE ::OnixS::Logging::SourceInfo(__FILE__, __LINE__, nullptr)
35 
36 
37 #ifdef _DEBUG
38 #define EXCEPTION_SOURCE_INFO DIRECTEDGE_SOURCE_INFO
39 #define LOG_SOURCE_INFO DIRECTEDGE_SOURCE_INFO
40 #else
41 #ifdef _TRACE
42 #define EXCEPTION_SOURCE_INFO DIRECTEDGE_SOURCE_FUNC
43 #define LOG_SOURCE_INFO DIRECTEDGE_SOURCE_FUNC
44 #else
45 #define EXCEPTION_SOURCE_INFO DIRECTEDGE_SOURCE_FUNC
46 #define LOG_SOURCE_INFO OnixS::Logging::SourceInfo()
47 #endif
48 #endif
49 
50 //////////////////////////////////////////////////////////////////////////
51 // format macros
52 
53 // declaration of formatting signature for types by const ref
54 #define DECL_FORMAT(ftype) \
55 TextBuilder & operator<<(TextBuilder & o, const ftype & obj)
56 
57 
58 // declaration of formatting signature for types by value
59 #define DECL_FORMAT_BYVAL(ftype) \
60 TextBuilder & operator<<(TextBuilder & o, ftype obj)
61 
62 // definition of formatting for types by const ref
63 #define STRUCT_FORMAT(ftype, fformat)\
64 TextBuilder & operator<<(TextBuilder & o, const ftype & obj) {\
65 return o << Util::indent(4) fformat << Util::indent(-4);\
66 }
67 
68 #define STRUCT_FORMAT_T(ftype, fformat)\
69 TextBuilder & operator<<(TextBuilder & o, const ftype & obj) {\
70 return o << '[' << #ftype << "]\n" << indent(4) fformat << indent(-4);\
71 }
72 
73 // definition of formatting for enums
74 #define ENUM_FORMAT(fenumbox, fformat)\
75 TextBuilder & operator<<(TextBuilder & o, fenumbox::Enum obj) {\
76 typedef fenumbox __FENUM_BOX__;\
77 switch(obj) { fformat default: if(obj ) o << int(obj) << " (?)";\
78  else format_nullptr_value(o); } return o; }
79 // single enum value formatting
80 #define FENUM(fenum) case __FENUM_BOX__::fenum: o << int(__FENUM_BOX__::fenum) << " ("#fenum")"; break;
81 
82 // definition of API formatting for enums
83 #define API_ENUM_FORMAT(fenumbox, fformat)\
84 const char ONIXS_API * enumToString(fenumbox::Enum value) {\
85 typedef fenumbox __FENUM_BOX__;\
86 switch(value) { fformat default: return "#Invalid enumeration value"; } }
87 
88 // single API enum value formatting
89 #define ENUM_STR(fenum) case __FENUM_BOX__::fenum: return #fenum;
90 
91 #define VAR(var) create_var_format(", "#var, var)
92 #define VARLN(var) '\n' << create_var_format(#var, var)
93 #define COMPLEX_FIELD(s) '\n' << indent(4) << create_var_format(#s, obj.s) << indent(-4)
94 #define FIELD(var) '\n' << create_var_format(#var, obj.var)
95 #define FIELD_AS(var, ftype) '\n' << create_var_format(#var, ftype(obj.var))
96 #define DATE_FIELD(var) FIELD_AS(var, SDateWrapper)
97 #define TIME_FIELD(var) FIELD_AS(var, STimeWrapper)
98 #define BOOL_FIELD(var) FIELD_AS(var, OMexBool::Enum)
99 
100 namespace OnixS {
101 namespace Eurex {
102 namespace MarketData {
103 namespace Implementation {
104 
105 #define ASSERT_ARG(arg, cond) if(arg cond) {} else \
106 throw ArgumentExceptionImpl("Argument value does not meet condition: "#arg" "#cond, #arg, EXCEPTION_SOURCE_INFO)
107 
108 #ifdef _DEBUG
109 #define DEBUG_ASSERT_ARG(arg, cond) ASSERT_ARG(arg, cond)
110 #else
111 #define DEBUG_ASSERT_ARG(arg, cond) ((void)0)
112 #endif
113 
114 #define ASSERT_COND(cond) if(cond) {} else \
115 throw OperationExceptionImpl("Object state does not meet condition: "#cond, EXCEPTION_SOURCE_INFO)
116 
117 #ifdef _DEBUG
118 #define DEBUG_ASSERT_COND(cond) ASSERT_COND(cond)
119 #else
120 #define DEBUG_ASSERT_COND(cond) ((void)0)
121 #endif
122 
123 #if (defined(_TRACE) || defined(_DEBUG))
124 #ifdef _DEBUG
125 #define DEFAULT_LOG_LEVEL Logging::LOG_LEVEL_DEBUG
126 #else
127 #define DEFAULT_LOG_LEVEL Logging::LOG_LEVEL_TRACE
128 #endif
129 #else
130 #define DEFAULT_LOG_LEVEL Logging::LOG_LEVEL_INFO
131 #endif
132 
133 
134 #ifdef _TRACE
135 /// Use this macro as first line of traced function
136 #define TRACE_STATE(state, logger) if(state.changed()) logger.log(ONIXS_LOG_TRACE << "|===> " BOOST_CURRENT_FUNCTION)
137 #else
138 #define TRACE_STATE(state, logger) do {} while(false)
139 #endif
140 
141 
142 #ifdef _TRACE
143 /// Use this macro as first line of traced function
144 #define TRACE_FUNC_MINI(logger) logger.log(ONIXS_LOG_TRACE << ">>> " BOOST_CURRENT_FUNCTION " >>>")
145 #else
146 #define TRACE_FUNC_MINI(logger) do {} while(false)
147 #endif
148 
149 typedef boost::scoped_ptr<HandlerCore::Common::HandlerLogger> LoggerPtr;
150 
151 using namespace Util;
152 
153 template<typename T>
155  const Util::ValuePtr name;
156  const T value;
157 
158  // construct from literal
159  template<size_t NLen>
160  VarFormatHelper(const char( & name_)[NLen], const T & value_)
161  : name(name_, NLen - 1 /* !!! do not include terminator */), value(value_) {}
162 };
163 
164 // helper function-dispatcher
165 template<size_t NLen, typename T>
166 VarFormatHelper<T> create_var_format(const char( & name)[NLen], const T & value)
167 {
168  return VarFormatHelper<T>(name, value);
169 };
170 
171 // dispatch unsigned char as unsigned int
172 template<size_t NLen>
173 VarFormatHelper<unsigned> create_var_format(const char( & name)[NLen], unsigned char value)
174 {
175  return VarFormatHelper<unsigned>(name, value);
176 };
177 
178 // to do not inference with unsigned char explicit declaration
179 template<size_t NLen>
180 VarFormatHelper<char> create_var_format(const char( & name)[NLen], char value)
181 {
182  return VarFormatHelper<char>(name, value);
183 };
184 
185 // dispatch char[NVal] field value as literal without zero terminator
186 // trims spaces at the end
187 template<size_t NLen, size_t NVal>
188 VarFormatHelper<ValuePtr> create_var_format(const char( & name)[NLen], const char( & value)[NVal])
189 {
190  // do trim
191  int last = -1;
192  const char * src = value;
193  char c;
194 
195  for (int i = 0; (i < NVal) && (c = *src++); i++)
196  if (c != ' ')
197  last = i;
198 
199  return VarFormatHelper<OnixS::Util::ValuePtr>(name, OnixS::Util::ValuePtr(value, last+1));
200 };
201 
202 TextBuilder & format_var_name(TextBuilder & o, ValuePtr name);
204 
205 
206 template<typename T>
207 inline TextBuilder & operator<<(TextBuilder & o, const VarFormatHelper<T> & var)
208 {
209  return format_var_name(o, var.name) << var.value;
210 }
211 
212 //DECL_FORMAT(SDateWrapper);
213 //DECL_FORMAT(STimeWrapper);
216 
217 void userExceptionHandler(HandlerCore::Common::HandlerLogger*, OnixS::Logging::LogFacility *, const char *contextName) ONIXS_NOEXCEPT;
218 
219 #define ONIXS_EXCEPTION_TRACED_CALLBACK_EX(callback, logger, logFacility, contextName) \
220 try { callback;\
221 logger->log( ONIXS_LOG_DEBUG[logFacility] << "Callback " << contextName << " called successfully");\
222 } catch(...) { OnixS::Eurex::MarketData::Implementation::userExceptionHandler(logger, logFacility, contextName); } \
223 
224 #define ONIXS_EXCEPTION_TRACED_CALLBACK(callback, contextName) ONIXS_EXCEPTION_TRACED_CALLBACK_EX(callback, logger_, this, contextName)
225 
226 
227 }}}}
boost::scoped_ptr< HandlerCore::Common::HandlerLogger > LoggerPtr
Util::TextBuilder TextBuilder
Definition: Formatting.h:43
char last(const std::string &str)
TextBuilder & format_var_name(TextBuilder &o, ValuePtr name)
VarFormatHelper(const char(&name_)[NLen], const T &value_)
Definition: Defines.h:30
#define DECL_FORMAT(ftype)
Definition: HandlerLogger.h:54
void userExceptionHandler(HandlerCore::Common::HandlerLogger *, OnixS::Logging::LogFacility *, const char *contextName) ONIXS_NOEXCEPT
TextBuilder & format_nullptr_value(TextBuilder &o)
VarFormatHelper< T > create_var_format(const char(&name)[NLen], const T &value)