OmniSciDB  cecceef8da
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
query_state::StdLog Class Reference

#include <QueryState.h>

+ Inheritance diagram for query_state::StdLog:
+ Collaboration diagram for query_state::StdLog:

Public Member Functions

template<typename... Pairs>
 StdLog (char const *file, unsigned line, char const *func, std::shared_ptr< Catalog_Namespace::SessionInfo > session_info, Pairs &&...pairs)
 
template<typename... Pairs>
 StdLog (char const *file, unsigned line, char const *func, std::shared_ptr< Catalog_Namespace::SessionInfo > session_info, std::shared_ptr< QueryState > query_state, Pairs &&...pairs)
 
template<typename... Pairs>
 StdLog (char const *file, unsigned line, char const *func, std::shared_ptr< QueryState > query_state, Pairs &&...pairs)
 
template<typename... Pairs>
 StdLog (char const *file, unsigned line, char const *func, Pairs &&...pairs)
 
 StdLog (StdLog const &)=delete
 
 StdLog (StdLog &&)=default
 
 ~StdLog ()
 
template<typename... Pairs>
void appendNameValuePairs (Pairs &&...pairs)
 
template<typename Units = std::chrono::milliseconds>
Units::rep duration () const
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const > 
getConstSessionInfo () const
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
getSessionInfo () const
 
void setQueryState (std::shared_ptr< QueryState >)
 
void setSessionInfo (std::shared_ptr< Catalog_Namespace::SessionInfo >)
 

Private Member Functions

void log (logger::Severity, char const *label)
 
void logCallStack (logger::Severity, char const *label)
 

Static Private Member Functions

static logger::Severity stdlogBeginSeverity (char const *func)
 

Private Attributes

std::shared_ptr
< Catalog_Namespace::SessionInfo
session_info_
 
std::shared_ptr< QueryStatequery_state_
 

Additional Inherited Members

- Protected Member Functions inherited from query_state::StdLogData
template<typename... Pairs>
 StdLogData (char const *file, unsigned line, char const *func, Pairs &&...pairs)
 
- Protected Attributes inherited from query_state::StdLogData
std::string const file_
 
unsigned const line_
 
char const *const func_
 
Clock::time_point const start_
 
int64_t const match_
 
std::list< std::string > name_value_pairs_
 
- Static Protected Attributes inherited from query_state::StdLogData
static std::atomic< int64_t > s_match {0}
 

Detailed Description

Definition at line 252 of file QueryState.h.

Constructor & Destructor Documentation

template<typename... Pairs>
query_state::StdLog::StdLog ( char const *  file,
unsigned  line,
char const *  func,
std::shared_ptr< Catalog_Namespace::SessionInfo session_info,
Pairs &&...  pairs 
)
inline

Definition at line 261 of file QueryState.h.

References log(), and stdlogBeginSeverity().

266  : StdLogData(file, line, func, std::forward<Pairs>(pairs)...)
267  , session_info_(std::move(session_info)) {
268  log(stdlogBeginSeverity(func), "stdlog_begin");
269  }
StdLogData(char const *file, unsigned line, char const *func, Pairs &&...pairs)
Definition: QueryState.h:240
static logger::Severity stdlogBeginSeverity(char const *func)
Definition: QueryState.cpp:169
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:253
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:177

+ Here is the call graph for this function:

template<typename... Pairs>
query_state::StdLog::StdLog ( char const *  file,
unsigned  line,
char const *  func,
std::shared_ptr< Catalog_Namespace::SessionInfo session_info,
std::shared_ptr< QueryState query_state,
Pairs &&...  pairs 
)
inline

Definition at line 272 of file QueryState.h.

References log(), and stdlogBeginSeverity().

278  : StdLogData(file, line, func, std::forward<Pairs>(pairs)...)
279  , session_info_(std::move(session_info))
280  , query_state_(std::move(query_state)) {
281  log(stdlogBeginSeverity(func), "stdlog_begin");
282  }
StdLogData(char const *file, unsigned line, char const *func, Pairs &&...pairs)
Definition: QueryState.h:240
static logger::Severity stdlogBeginSeverity(char const *func)
Definition: QueryState.cpp:169
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:253
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:254
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:177

+ Here is the call graph for this function:

template<typename... Pairs>
query_state::StdLog::StdLog ( char const *  file,
unsigned  line,
char const *  func,
std::shared_ptr< QueryState query_state,
Pairs &&...  pairs 
)
inline

Definition at line 285 of file QueryState.h.

References log(), and stdlogBeginSeverity().

290  : StdLogData(file, line, func, std::forward<Pairs>(pairs)...)
291  , query_state_(std::move(query_state)) {
292  log(stdlogBeginSeverity(func), "stdlog_begin");
293  }
StdLogData(char const *file, unsigned line, char const *func, Pairs &&...pairs)
Definition: QueryState.h:240
static logger::Severity stdlogBeginSeverity(char const *func)
Definition: QueryState.cpp:169
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:254
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:177

+ Here is the call graph for this function:

template<typename... Pairs>
query_state::StdLog::StdLog ( char const *  file,
unsigned  line,
char const *  func,
Pairs &&...  pairs 
)
inline

Definition at line 295 of file QueryState.h.

References log(), and stdlogBeginSeverity().

296  : StdLogData(file, line, func, std::forward<Pairs>(pairs)...) {
297  log(stdlogBeginSeverity(func), "stdlog_begin");
298  }
StdLogData(char const *file, unsigned line, char const *func, Pairs &&...pairs)
Definition: QueryState.h:240
static logger::Severity stdlogBeginSeverity(char const *func)
Definition: QueryState.cpp:169
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:177

+ Here is the call graph for this function:

query_state::StdLog::StdLog ( StdLog const &  )
delete
query_state::StdLog::StdLog ( StdLog &&  )
default
query_state::StdLog::~StdLog ( )

Definition at line 223 of file QueryState.cpp.

References logger::DEBUG1, logger::INFO, log(), logCallStack(), query_state_, and session_info_.

223  {
224  log(logger::Severity::INFO, "stdlog");
225  logCallStack(logger::Severity::DEBUG1, "stacked_times");
226  if (query_state_) {
227  query_state_->setLogged(true);
228  }
229  if (session_info_) {
230  session_info_->update_last_used_time();
231  }
232 }
void logCallStack(logger::Severity, char const *label)
Definition: QueryState.cpp:213
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:253
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:254
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:177

+ Here is the call graph for this function:

Member Function Documentation

template<typename... Pairs>
void query_state::StdLog::appendNameValuePairs ( Pairs &&...  pairs)
inline

Definition at line 303 of file QueryState.h.

References query_state::StdLogData::name_value_pairs_, and to_string().

Referenced by MapDHandler::connect_impl().

303  {
304  static_assert(sizeof...(Pairs) % 2 == 0,
305  "appendNameValuePairs() requires an even number of parameters.");
306  name_value_pairs_.splice(name_value_pairs_.cend(),
307  {to_string(std::forward<Pairs>(pairs))...});
308  }
std::string to_string(char const *&&v)
std::list< std::string > name_value_pairs_
Definition: QueryState.h:238

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename Units = std::chrono::milliseconds>
Units::rep query_state::StdLog::duration ( ) const
inline

Definition at line 310 of file QueryState.h.

References query_state::StdLogData::start_.

310  {
311  return std::chrono::duration_cast<Units>(Clock::now() - start_).count();
312  }
Clock::time_point const start_
Definition: QueryState.h:236
std::shared_ptr< Catalog_Namespace::SessionInfo const > query_state::StdLog::getConstSessionInfo ( ) const

Definition at line 130 of file QueryState.cpp.

References session_info_.

Referenced by MapDHandler::get_completion_hints_unsorted().

131  {
132  return session_info_;
133 }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:253

+ Here is the caller graph for this function:

std::shared_ptr< Catalog_Namespace::SessionInfo > query_state::StdLog::getSessionInfo ( ) const

Definition at line 135 of file QueryState.cpp.

References session_info_.

Referenced by MapDHandler::get_table_details_impl().

135  {
136  return session_info_;
137 }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:253

+ Here is the caller graph for this function:

void query_state::StdLog::log ( logger::Severity  severity,
char const *  label 
)
private

Definition at line 177 of file QueryState.cpp.

References logger::fast_logging_check(), query_state::StdLogData::file_, query_state::StdLogData::func_, hide_sensitive_data_from_query(), query_state::StdLogData::line_, query_state::StdLogData::match_, query_state::StdLogData::name_value_pairs_, query_state_, and session_info_.

Referenced by StdLog(), and ~StdLog().

177  {
178  if (logger::fast_logging_check(severity)) {
179  std::stringstream ss;
180  ss << file_ << ':' << line_ << ' ' << label << ' ' << func_ << ' ' << match_ << ' '
181  << duration<std::chrono::milliseconds>() << ' ';
182  if (session_info_) {
183  ss << SessionInfoFormatter{*session_info_} << ' ';
184  } else if (query_state_ && query_state_->getSessionData()) {
185  ss << *query_state_->getSessionData() << ' ';
186  } else {
187  ss << " "; // 3 spaces for 3 empty strings
188  }
189  auto const& nv = name_value_pairs_;
190  if (nv.empty() && (!query_state_ || query_state_->emptyLog())) {
191  ss << ' '; // 1 space for final empty names/values arrays
192  } else {
193  // All values are logged after all names, so separate values stream is needed.
194  std::stringstream values;
195  unsigned nvalues = 0;
196  if (query_state_ && !query_state_->getQueryStr().empty()) {
197  ss << (nvalues ? ',' : '{') << std::quoted("query_str", '"', '"');
198  values << (nvalues++ ? ',' : '{')
199  << std::quoted(hide_sensitive_data_from_query(query_state_->getQueryStr()),
200  '"',
201  '"');
202  }
203  for (auto itr = nv.cbegin(); itr != nv.cend(); ++itr) {
204  ss << (nvalues ? ',' : '{') << std::quoted(*itr, '"', '"');
205  values << (nvalues++ ? ',' : '{') << std::quoted(*++itr, '"', '"');
206  }
207  ss << "} " << values.rdbuf() << '}';
208  }
209  BOOST_LOG_SEV(logger::gSeverityLogger::get(), severity) << ss.rdbuf();
210  }
211 }
std::string hide_sensitive_data_from_query(std::string const &query_str)
unsigned const line_
Definition: QueryState.h:234
std::string const file_
Definition: QueryState.h:233
std::list< std::string > name_value_pairs_
Definition: QueryState.h:238
bool fast_logging_check(Channel)
Definition: Logger.h:174
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:253
int64_t const match_
Definition: QueryState.h:237
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:254
char const *const func_
Definition: QueryState.h:235

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void query_state::StdLog::logCallStack ( logger::Severity  severity,
char const *  label 
)
private

Definition at line 213 of file QueryState.cpp.

References logger::fast_logging_check(), query_state::StdLogData::file_, query_state::StdLogData::func_, query_state::StdLogData::line_, query_state::StdLogData::match_, and query_state_.

Referenced by ~StdLog().

213  {
214  if (logger::fast_logging_check(severity) && query_state_) {
215  std::stringstream ss;
216  ss << file_ << ':' << line_ << ' ' << label << ' ' << func_ << ' ' << match_
217  << " total time " << duration<std::chrono::milliseconds>() << " ms";
218  query_state_->logCallStack(ss);
219  BOOST_LOG_SEV(logger::gSeverityLogger::get(), severity) << ss.rdbuf();
220  }
221 }
unsigned const line_
Definition: QueryState.h:234
std::string const file_
Definition: QueryState.h:233
bool fast_logging_check(Channel)
Definition: Logger.h:174
int64_t const match_
Definition: QueryState.h:237
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:254
char const *const func_
Definition: QueryState.h:235

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void query_state::StdLog::setQueryState ( std::shared_ptr< QueryState query_state)

Definition at line 234 of file QueryState.cpp.

References query_state_.

Referenced by MapDHandler::get_table_details_impl().

234  {
235  query_state_ = std::move(query_state);
236 }
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:254

+ Here is the caller graph for this function:

void query_state::StdLog::setSessionInfo ( std::shared_ptr< Catalog_Namespace::SessionInfo session_info)

Definition at line 238 of file QueryState.cpp.

References session_info_.

Referenced by MapDHandler::connect_impl().

239  {
240  session_info_ = std::move(session_info);
241 }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:253

+ Here is the caller graph for this function:

logger::Severity query_state::StdLog::stdlogBeginSeverity ( char const *  func)
staticprivate

Definition at line 169 of file QueryState.cpp.

References logger::DEBUG1, and logger::INFO.

Referenced by StdLog().

169  {
170  logger::Severity const defaultSeverity = logger::Severity::DEBUG1;
171  static std::unordered_map<std::string_view, logger::Severity> const map{
172  {"sql_execute", logger::Severity::INFO}};
173  auto const itr = map.find(func);
174  return itr == map.cend() ? defaultSeverity : itr->second;
175 }
Severity
Definition: Logger.h:73

+ Here is the caller graph for this function:

Member Data Documentation

std::shared_ptr<QueryState> query_state::StdLog::query_state_
private

Definition at line 254 of file QueryState.h.

Referenced by log(), logCallStack(), setQueryState(), and ~StdLog().

std::shared_ptr<Catalog_Namespace::SessionInfo> query_state::StdLog::session_info_
private

Definition at line 253 of file QueryState.h.

Referenced by getConstSessionInfo(), getSessionInfo(), log(), setSessionInfo(), and ~StdLog().


The documentation for this class was generated from the following files: