OnixS C++ SGX Titan ITCH Market Data Handler  1.2.2
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 ONIXS_HANDLER_NAMESPACE_BEGIN
23 
24 using namespace std;
25 using namespace HandlerCore::Common;
26 
27 char last (const std::string &str)
28 {
29  if(size_t len = str.length())
30  return str[len - 1];
31 
32  return 0;
33 }
34 
35 template<size_t N>
36 bool oneof(const char c, const char( &literal)[N])
37 {
38  for(int i = N; i; i--)
39  if(c == literal[i])
40  return true;
41 
42  return false;
43 }
44 
45 
46 TextBuilder & format_null_value(TextBuilder & o)
47 {
48  o.appendNoIndent("*", 1);
49  return o;
50 }
51 
52 
53 TextBuilder & format_var_name(TextBuilder & o, ValuePtr name)
54 {
55  return o << name << '=';
56 }
57 
58 // take string in quotes
59 TextBuilder & operator<<(TextBuilder & o, const VarFormatHelper<ValuePtr> & var)
60 {
61  format_var_name(o, var.name);
62 
63  if(var.value.length_)
64  return o << "\"" << var.value << "\"";
65 
66  return format_null_value(o);
67 }
68 
69 // take char in quotes
70 TextBuilder & operator<<(TextBuilder & o, const VarFormatHelper<char> & var)
71 {
72  format_var_name(o, var.name);
73 
74  if(var.value)
75  return o << "'" << var.value << "'";
76 
77  return format_null_value(o);
78 }
79 
80 void userExceptionHandler(HandlerLogger* logger, OnixS::Logging::LogFacility *logFacility, const char *contextName) ONIXS_NOEXCEPT
81 {
82  BOOST_ASSERT(logFacility);
83  BOOST_ASSERT(contextName);
84 
85  try
86  {
87  throw;
88  }
89  catch(const std::exception &ex)
90  {
91  if(logger)
92  logger->log( ONIXS_LOG_ERROR[logFacility] << "Exception inside " << contextName << " callback: " << ex.what());
93  }
94  catch(...)
95  {
96  if(logger)
97  logger->log( ONIXS_LOG_ERROR[logFacility] << "Unknown exception inside " << contextName << " callback.");
98  }
99 }
100 
101 Logging::FileOutput::PermissionOption getOutputPermission(LogFilePermission::Enum value)
102 {
103  Logging::FileOutput::PermissionOption result = Logging::FileOutput::NoSet;
104 
105  if(value & LogFilePermission::ReadOwnerOnly)
106  result = result | Logging::FileOutput::ReadOwner;
107 
108  if(value & LogFilePermission::ReadAll)
109  result = result | Logging::FileOutput::ReadAll;
110 
111  if(value & LogFilePermission::WriteOwnerOnly)
112  result = result | Logging::FileOutput::WriteOwner;
113 
114  if(value & LogFilePermission::WriteAll)
115  result = result | Logging::FileOutput::WriteAll;
116 
117  return result;
118 }
119 
120 ONIXS_HANDLER_NAMESPACE_END
void userExceptionHandler(HandlerLogger *logger, OnixS::Logging::LogFacility *logFacility, const char *contextName) ONIXS_NOEXCEPT
STL namespace.
TextBuilder & format_var_name(TextBuilder &o, ValuePtr name)
bool oneof(const char c, const char(&literal)[N])
Logging::FileOutput::PermissionOption getOutputPermission(LogFilePermission::Enum value)
char last(const std::string &str)
TextBuilder & format_null_value(TextBuilder &o)