OnixS C++ Eurex T7 Market and Reference Data Interface (EMDI, RDI, EOBI) Handlers  7.0.3
API documentation
HandlerLogger.cpp
Go to the documentation of this file.
1 /*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable ONIXS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 
20 #include "HandlerLogger.h"
21 
22 #if defined(_DEBUG) && defined(WIN32) && defined(DEBUG_MEM)
23 #undef new
24 #define new DEBUG_NEW
25 #endif
26 
27 using namespace std;
28 
29 namespace OnixS {
30 namespace Eurex {
31 namespace MarketData {
32 namespace Implementation {
33 
34 char last (const std::string &str)
35 {
36  if(size_t len = str.length())
37  return str[len - 1];
38 
39  return 0;
40 }
41 
42 template<size_t N>
43 bool oneof(const char c, const char( &literal)[N])
44 {
45  for(int i = N; i; i--)
46  if(c == literal[i])
47  return true;
48 
49  return false;
50 }
51 
52 
54 {
55  o.appendNoIndent("*", 1);
56  return o;
57 }
58 
59 
61 {
62  return o << name << '=';
63 }
64 
65 // take string in quotes
66 TextBuilder & operator<<(TextBuilder & o, const VarFormatHelper<ValuePtr> & var)
67 {
68  format_var_name(o, var.name);
69 
70  if(var.value.length_)
71  return o << "\"" << var.value << "\"";
72 
73  return format_null_value(o);
74 }
75 
76 // take char in quotes
77 TextBuilder & operator<<(TextBuilder & o, const VarFormatHelper<char> & var)
78 {
79  format_var_name(o, var.name);
80 
81  if(var.value)
82  return o << "'" << var.value << "'";
83 
84  return format_null_value(o);
85 }
86 
87 void userExceptionHandler(LoggerPtr logger, OnixS::Logging::LogFacility *logFacility, const char *contextName)
88 {
89  userExceptionHandler(logger.get(), logFacility, contextName);
90 }
91 
92 void userExceptionHandler(HandlerCore::Common::HandlerLogger* logger, OnixS::Logging::LogFacility *logFacility, const char *contextName)
93 {
94  try
95  {
96  throw;
97  }
98  catch(const std::exception &ex)
99  {
100  logger->log( ONIXS_LOG_ERROR[logFacility] << "Exception inside " << contextName << " callback: " << ex.what());
101  }
102  catch(...)
103  {
104  logger->log( ONIXS_LOG_ERROR[logFacility] << "Unknown exception inside " << contextName << " callback.");
105  }
106 }
107 
108 Logging::FileOutput::PermissionOption getOutputPermission(LogFilePermission::Enum value)
109 {
110  Logging::FileOutput::PermissionOption result = Logging::FileOutput::NoSet;
111 
112  if(value & LogFilePermission::ReadOwnerOnly)
113  result = result | Logging::FileOutput::ReadOwner;
114 
115  if(value & LogFilePermission::ReadAll)
116  result = result | Logging::FileOutput::ReadAll;
117 
118  if(value & LogFilePermission::WriteOwnerOnly)
119  result = result | Logging::FileOutput::WriteOwner;
120 
121  if(value & LogFilePermission::WriteAll)
122  result = result | Logging::FileOutput::WriteAll;
123 
124  return result;
125 }
126 
127 }}}}
128 
void userExceptionHandler(HandlerCore::Common::HandlerLogger *, OnixS::Logging::LogFacility *, const char *contextName)
boost::scoped_ptr< HandlerCore::Common::HandlerLogger > LoggerPtr
STL namespace.
Util::TextBuilder TextBuilder
Definition: Formatting.h:42
char last(const std::string &str)
TextBuilder & format_var_name(TextBuilder &o, ValuePtr name)
TextBuilder & format_null_value(TextBuilder &o)
Definition: Group.h:25
OnixS::Logging::FileOutput::PermissionOption getOutputPermission(LogFilePermission::Enum value)
bool oneof(const char c, const char(&literal)[N])