OmniSciDB  fe05a0c208
 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 256 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 265 of file QueryState.h.

References log(), and stdlogBeginSeverity().

270  : StdLogData(file, line, func, std::forward<Pairs>(pairs)...)
271  , session_info_(std::move(session_info)) {
272  log(stdlogBeginSeverity(func), "stdlog_begin");
273  }
StdLogData(char const *file, unsigned line, char const *func, Pairs &&...pairs)
Definition: QueryState.h:244
static logger::Severity stdlogBeginSeverity(char const *func)
Definition: QueryState.cpp:181
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:257
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:206

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

References log(), and stdlogBeginSeverity().

282  : StdLogData(file, line, func, std::forward<Pairs>(pairs)...)
283  , session_info_(std::move(session_info))
284  , query_state_(std::move(query_state)) {
285  log(stdlogBeginSeverity(func), "stdlog_begin");
286  }
StdLogData(char const *file, unsigned line, char const *func, Pairs &&...pairs)
Definition: QueryState.h:244
static logger::Severity stdlogBeginSeverity(char const *func)
Definition: QueryState.cpp:181
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:257
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:258
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:206

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

References log(), and stdlogBeginSeverity().

294  : StdLogData(file, line, func, std::forward<Pairs>(pairs)...)
295  , query_state_(std::move(query_state)) {
296  log(stdlogBeginSeverity(func), "stdlog_begin");
297  }
StdLogData(char const *file, unsigned line, char const *func, Pairs &&...pairs)
Definition: QueryState.h:244
static logger::Severity stdlogBeginSeverity(char const *func)
Definition: QueryState.cpp:181
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:258
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:206

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

References log(), and stdlogBeginSeverity().

300  : StdLogData(file, line, func, std::forward<Pairs>(pairs)...) {
301  log(stdlogBeginSeverity(func), "stdlog_begin");
302  }
StdLogData(char const *file, unsigned line, char const *func, Pairs &&...pairs)
Definition: QueryState.h:244
static logger::Severity stdlogBeginSeverity(char const *func)
Definition: QueryState.cpp:181
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:206

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

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

252  {
253  log(logger::Severity::INFO, "stdlog");
254  logCallStack(logger::Severity::DEBUG1, "stacked_times");
255  if (query_state_) {
256  query_state_->setLogged(true);
257  }
258  if (session_info_) {
259  session_info_->update_last_used_time();
260  }
261 }
void logCallStack(logger::Severity, char const *label)
Definition: QueryState.cpp:242
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:257
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:258
void log(logger::Severity, char const *label)
Definition: QueryState.cpp:206

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

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

Referenced by DBHandler::connect_impl().

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

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

References count, and query_state::StdLogData::start_.

314  {
315  return std::chrono::duration_cast<Units>(Clock::now() - start_).count();
316  }
int count
Clock::time_point const start_
Definition: QueryState.h:240
std::shared_ptr< Catalog_Namespace::SessionInfo const > query_state::StdLog::getConstSessionInfo ( ) const

Definition at line 141 of file QueryState.cpp.

References session_info_.

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

142  {
143  return session_info_;
144 }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:257

+ Here is the caller graph for this function:

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

Definition at line 146 of file QueryState.cpp.

References session_info_.

Referenced by DBHandler::get_table_details_impl().

146  {
147  return session_info_;
148 }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:257

+ Here is the caller graph for this function:

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

Definition at line 206 of file QueryState.cpp.

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

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

206  {
207  if (logger::fast_logging_check(severity)) {
208  std::stringstream ss;
209  ss << logger::thread_id() << ' ' << file_ << ':' << line_ << ' ' << label << ' '
210  << func_ << ' ' << match_ << ' ' << duration<std::chrono::milliseconds>() << ' ';
211  if (session_info_) {
212  ss << SessionInfoFormatter{*session_info_} << ' ';
213  } else if (query_state_ && query_state_->getSessionData()) {
214  ss << *query_state_->getSessionData() << ' ';
215  } else {
216  ss << " "; // 3 spaces for 3 empty strings
217  }
218  auto const& nv = name_value_pairs_;
219  if (nv.empty() && (!query_state_ || query_state_->emptyLog())) {
220  ss << ' '; // 1 space for final empty names/values arrays
221  } else {
222  // All values are logged after all names, so separate values stream is needed.
223  std::stringstream values;
224  unsigned nvalues = 0;
225  if (query_state_ && !query_state_->getQueryStr().empty()) {
226  ss << (nvalues ? ',' : '{') << std::quoted("query_str", '"', '"');
227  values << (nvalues++ ? ',' : '{')
228  << std::quoted(hide_sensitive_data_from_query(query_state_->getQueryStr()),
229  '"',
230  '"');
231  }
232  for (auto itr = nv.cbegin(); itr != nv.cend(); ++itr) {
233  ss << (nvalues ? ',' : '{') << std::quoted(*itr, '"', '"');
234  values << (nvalues++ ? ',' : '{') << std::quoted(*++itr, '"', '"');
235  }
236  ss << "} " << values.rdbuf() << '}';
237  }
238  BOOST_LOG_SEV(logger::gSeverityLogger::get(), severity) << ss.rdbuf();
239  }
240 }
std::string hide_sensitive_data_from_query(std::string const &query_str)
unsigned const line_
Definition: QueryState.h:238
std::string const file_
Definition: QueryState.h:237
std::list< std::string > name_value_pairs_
Definition: QueryState.h:242
bool fast_logging_check(Channel)
Definition: Logger.h:180
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:257
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:258
ThreadId thread_id()
Definition: Logger.cpp:732

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

242  {
243  if (logger::fast_logging_check(severity) && query_state_) {
244  std::stringstream ss;
245  ss << file_ << ':' << line_ << ' ' << label << ' ' << func_ << ' ' << match_
246  << " total time " << duration<std::chrono::milliseconds>() << " ms";
247  query_state_->logCallStack(ss);
248  BOOST_LOG_SEV(logger::gSeverityLogger::get(), severity) << ss.rdbuf();
249  }
250 }
unsigned const line_
Definition: QueryState.h:238
std::string const file_
Definition: QueryState.h:237
bool fast_logging_check(Channel)
Definition: Logger.h:180
int64_t const match_
Definition: QueryState.h:241
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:258
char const *const func_
Definition: QueryState.h:239

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

References query_state_.

Referenced by DBHandler::get_table_details_impl().

263  {
264  query_state_ = std::move(query_state);
265 }
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:258

+ Here is the caller graph for this function:

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

Definition at line 267 of file QueryState.cpp.

References session_info_.

Referenced by DBHandler::connect_impl().

268  {
269  session_info_ = std::move(session_info);
270 }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:257

+ Here is the caller graph for this function:

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

Definition at line 181 of file QueryState.cpp.

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

Referenced by StdLog().

181  {
182  logger::Severity const defaultSeverity = logger::Severity::DEBUG1;
183  static std::unordered_map<std::string_view, logger::Severity> const map{
184  {"connect", logger::Severity::INFO},
185  {"disconnect", logger::Severity::INFO},
186  {"switch_database", logger::Severity::INFO},
187  {"clone_session", logger::Severity::INFO},
188  {"get_tables_meta", logger::Severity::INFO},
189  {"get_table_details", logger::Severity::INFO},
190  {"sql_execute", logger::Severity::INFO},
191  {"sql_execute_df", logger::Severity::INFO},
192  {"sql_execute_gdf", logger::Severity::INFO},
193  {"sql_validate", logger::Severity::INFO},
194  {"render_vega", logger::Severity::INFO},
195  {"get_result_row_for_pixel", logger::Severity::INFO},
196  {"check_table_consistency", logger::Severity::INFO},
197  {"start_query", logger::Severity::INFO},
198  {"execute_query_step", logger::Severity::INFO},
199  {"broadcast_serialized_rows", logger::Severity::INFO},
200  {"start_render_query", logger::Severity::INFO},
201  {"execute_next_render_step", logger::Severity::INFO}};
202  auto const itr = map.find(func);
203  return itr == map.cend() ? defaultSeverity : itr->second;
204 }
Severity
Definition: Logger.h:79

+ Here is the caller graph for this function:

Member Data Documentation

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

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

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


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