OmniSciDB  ca0c39ec8f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 262 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 271 of file QueryState.h.

References log(), and stdlogBeginSeverity().

276  : StdLogData(file, line, func, std::forward<Pairs>(pairs)...)
277  , session_info_(std::move(session_info)) {
278  log(stdlogBeginSeverity(func), "stdlog_begin");
279  }
StdLogData(char const *file, unsigned line, char const *func, Pairs &&...pairs)
Definition: QueryState.h:250
static logger::Severity stdlogBeginSeverity(char const *func)
Definition: QueryState.cpp:199
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:263
tuple line
Definition: parse_ast.py:10
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:224

+ 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 282 of file QueryState.h.

References log(), and stdlogBeginSeverity().

288  : StdLogData(file, line, func, std::forward<Pairs>(pairs)...)
289  , session_info_(std::move(session_info))
290  , query_state_(std::move(query_state)) {
291  log(stdlogBeginSeverity(func), "stdlog_begin");
292  }
StdLogData(char const *file, unsigned line, char const *func, Pairs &&...pairs)
Definition: QueryState.h:250
static logger::Severity stdlogBeginSeverity(char const *func)
Definition: QueryState.cpp:199
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:263
tuple line
Definition: parse_ast.py:10
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:264
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:224

+ 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 295 of file QueryState.h.

References log(), and stdlogBeginSeverity().

300  : StdLogData(file, line, func, std::forward<Pairs>(pairs)...)
301  , query_state_(std::move(query_state)) {
302  log(stdlogBeginSeverity(func), "stdlog_begin");
303  }
StdLogData(char const *file, unsigned line, char const *func, Pairs &&...pairs)
Definition: QueryState.h:250
static logger::Severity stdlogBeginSeverity(char const *func)
Definition: QueryState.cpp:199
tuple line
Definition: parse_ast.py:10
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:264
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:224

+ 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 305 of file QueryState.h.

References log(), and stdlogBeginSeverity().

306  : StdLogData(file, line, func, std::forward<Pairs>(pairs)...) {
307  log(stdlogBeginSeverity(func), "stdlog_begin");
308  }
StdLogData(char const *file, unsigned line, char const *func, Pairs &&...pairs)
Definition: QueryState.h:250
static logger::Severity stdlogBeginSeverity(char const *func)
Definition: QueryState.cpp:199
tuple line
Definition: parse_ast.py:10
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:224

+ 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 271 of file QueryState.cpp.

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

271  {
272  log(logger::Severity::INFO, "stdlog");
273  logCallStack(logger::Severity::DEBUG1, "stacked_times");
274  if (query_state_) {
275  query_state_->setLogged(true);
276  }
277  if (session_info_) {
278  session_info_->update_last_used_time();
279  }
280 }
void logCallStack(logger::Severity, char const *label)
Definition: QueryState.cpp:261
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:263
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:264
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:224

+ 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 313 of file QueryState.h.

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

Referenced by DBHandler::connect_impl().

313  {
314  static_assert(sizeof...(Pairs) % 2 == 0,
315  "appendNameValuePairs() requires an even number of parameters.");
316  name_value_pairs_.splice(name_value_pairs_.cend(),
317  {to_string(std::forward<Pairs>(pairs))...});
318  }
std::string to_string(char const *&&v)
std::list< std::string > name_value_pairs_
Definition: QueryState.h:248

+ 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 320 of file QueryState.h.

References query_state::StdLogData::start_.

320  {
321  return std::chrono::duration_cast<Units>(Clock::now() - start_).count();
322  }
Clock::time_point const start_
Definition: QueryState.h:246
std::shared_ptr< Catalog_Namespace::SessionInfo const > query_state::StdLog::getConstSessionInfo ( ) const

Definition at line 159 of file QueryState.cpp.

References session_info_.

Referenced by DBHandler::connect_impl(), and DBHandler::get_completion_hints_unsorted().

160  {
161  return session_info_;
162 }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:263

+ Here is the caller graph for this function:

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

Definition at line 164 of file QueryState.cpp.

References session_info_.

Referenced by DBHandler::get_table_details_impl().

164  {
165  return session_info_;
166 }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:263

+ Here is the caller graph for this function:

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

Definition at line 224 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_, logger::query_id(), query_state_, session_info_, and logger::thread_id().

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

224  {
225  if (logger::fast_logging_check(severity)) {
226  std::stringstream ss;
227  ss << logger::query_id() << ' ' << logger::thread_id() << ' ' << file_ << ':' << line_
228  << ' ' << label << ' ' << func_ << ' ' << match_ << ' '
229  << duration<std::chrono::milliseconds>() << ' ';
230  if (session_info_) {
231  ss << SessionInfoFormatter{*session_info_} << ' ';
232  } else if (query_state_ && query_state_->getSessionData()) {
233  ss << *query_state_->getSessionData() << ' ';
234  } else {
235  ss << " "; // 3 spaces for 3 empty strings
236  }
237  auto const& nv = name_value_pairs_;
238  if (nv.empty() && (!query_state_ || query_state_->emptyLog())) {
239  ss << ' '; // 1 space for final empty names/values arrays
240  } else {
241  // All values are logged after all names, so separate values stream is needed.
242  std::stringstream values;
243  unsigned nvalues = 0;
244  if (query_state_ && !query_state_->getQueryStr().empty()) {
245  ss << (nvalues ? ',' : '{') << std::quoted("query_str", '"', '"');
246  values << (nvalues++ ? ',' : '{')
247  << std::quoted(hide_sensitive_data_from_query(query_state_->getQueryStr()),
248  '"',
249  '"');
250  }
251  for (auto itr = nv.cbegin(); itr != nv.cend(); ++itr) {
252  ss << (nvalues ? ',' : '{') << std::quoted(*itr, '"', '"');
253  values << (nvalues++ ? ',' : '{') << std::quoted(*++itr, '"', '"');
254  }
255  ss << "} " << values.rdbuf() << '}';
256  }
257  BOOST_LOG_SEV(logger::gSeverityLogger::get(), severity) << ss.rdbuf();
258  }
259 }
std::string hide_sensitive_data_from_query(std::string const &query_str)
unsigned const line_
Definition: QueryState.h:244
std::string const file_
Definition: QueryState.h:243
std::list< std::string > name_value_pairs_
Definition: QueryState.h:248
bool fast_logging_check(Channel)
Definition: Logger.h:196
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:263
int64_t const match_
Definition: QueryState.h:247
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:264
ThreadId thread_id()
Definition: Logger.cpp:820
QueryId query_id()
Definition: Logger.cpp:473
char const *const func_
Definition: QueryState.h:245

+ 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 261 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().

261  {
262  if (logger::fast_logging_check(severity) && query_state_) {
263  std::stringstream ss;
264  ss << file_ << ':' << line_ << ' ' << label << ' ' << func_ << ' ' << match_
265  << " total time " << duration<std::chrono::milliseconds>() << " ms";
266  query_state_->logCallStack(ss);
267  BOOST_LOG_SEV(logger::gSeverityLogger::get(), severity) << ss.rdbuf();
268  }
269 }
unsigned const line_
Definition: QueryState.h:244
std::string const file_
Definition: QueryState.h:243
bool fast_logging_check(Channel)
Definition: Logger.h:196
int64_t const match_
Definition: QueryState.h:247
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:264
char const *const func_
Definition: QueryState.h:245

+ 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 282 of file QueryState.cpp.

References query_state_.

Referenced by DBHandler::get_table_details_impl().

282  {
283  query_state_ = std::move(query_state);
284 }
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:264

+ Here is the caller graph for this function:

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

Definition at line 286 of file QueryState.cpp.

References session_info_.

Referenced by DBHandler::connect_impl().

287  {
288  session_info_ = std::move(session_info);
289 }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:263

+ Here is the caller graph for this function:

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

Definition at line 199 of file QueryState.cpp.

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

Referenced by StdLog().

199  {
200  logger::Severity const defaultSeverity = logger::Severity::DEBUG1;
201  static std::unordered_map<std::string_view, logger::Severity> const map{
202  {"connect", logger::Severity::INFO},
203  {"disconnect", logger::Severity::INFO},
204  {"switch_database", logger::Severity::INFO},
205  {"clone_session", logger::Severity::INFO},
206  {"get_tables_meta", logger::Severity::INFO},
207  {"get_table_details", logger::Severity::INFO},
208  {"sql_execute", logger::Severity::INFO},
209  {"sql_execute_df", logger::Severity::INFO},
210  {"sql_execute_gdf", logger::Severity::INFO},
211  {"sql_validate", logger::Severity::INFO},
212  {"render_vega", logger::Severity::INFO},
213  {"get_result_row_for_pixel", logger::Severity::INFO},
214  {"check_table_consistency", logger::Severity::INFO},
215  {"start_query", logger::Severity::INFO},
216  {"execute_query_step", logger::Severity::INFO},
217  {"broadcast_serialized_rows", logger::Severity::INFO},
218  {"start_render_query", logger::Severity::INFO},
219  {"execute_next_render_step", logger::Severity::INFO}};
220  auto const itr = map.find(func);
221  return itr == map.cend() ? defaultSeverity : itr->second;
222 }
Severity
Definition: Logger.h:100

+ Here is the caller graph for this function:

Member Data Documentation

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

Definition at line 264 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 263 of file QueryState.h.

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


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