OmniSciDB  baf940c279
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::SessionInfogetSessionInfo () 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::SessionInfosession_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

◆ StdLog() [1/6]

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.

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

◆ StdLog() [2/6]

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.

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  }
static logger::Severity stdlogBeginSeverity(char const *func)
Definition: QueryState.cpp:169
StdLogData(char const *file, unsigned line, char const *func, Pairs &&... pairs)
Definition: QueryState.h:240
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:194

◆ StdLog() [3/6]

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.

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

◆ StdLog() [4/6]

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.

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

◆ StdLog() [5/6]

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

◆ StdLog() [6/6]

query_state::StdLog::StdLog ( StdLog &&  )
default

◆ ~StdLog()

query_state::StdLog::~StdLog ( )

Definition at line 240 of file QueryState.cpp.

References logger::DEBUG1, logger::INFO, and query_state::Timer::query_state_.

240  {
241  log(logger::Severity::INFO, "stdlog");
242  logCallStack(logger::Severity::DEBUG1, "stacked_times");
243  if (query_state_) {
244  query_state_->setLogged(true);
245  }
246  if (session_info_) {
247  session_info_->update_last_used_time();
248  }
249 }
void logCallStack(logger::Severity, char const *label)
Definition: QueryState.cpp:230
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:194

Member Function Documentation

◆ appendNameValuePairs()

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

Definition at line 303 of file QueryState.h.

References to_string().

Referenced by DBHandler::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:

◆ duration()

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

Definition at line 310 of file QueryState.h.

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

◆ getConstSessionInfo()

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

Definition at line 130 of file QueryState.cpp.

Referenced by DBHandler::connect_impl(), and DBHandler::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:

◆ getSessionInfo()

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

Definition at line 135 of file QueryState.cpp.

Referenced by DBHandler::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:

◆ log()

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

Definition at line 194 of file QueryState.cpp.

References logger::fast_logging_check(), hide_sensitive_data_from_query(), query_state::Timer::query_state_, and logger::thread_id().

194  {
195  if (logger::fast_logging_check(severity)) {
196  std::stringstream ss;
197  ss << logger::thread_id() << ' ' << file_ << ':' << line_ << ' ' << label << ' '
198  << func_ << ' ' << match_ << ' ' << duration<std::chrono::milliseconds>() << ' ';
199  if (session_info_) {
200  ss << SessionInfoFormatter{*session_info_} << ' ';
201  } else if (query_state_ && query_state_->getSessionData()) {
202  ss << *query_state_->getSessionData() << ' ';
203  } else {
204  ss << " "; // 3 spaces for 3 empty strings
205  }
206  auto const& nv = name_value_pairs_;
207  if (nv.empty() && (!query_state_ || query_state_->emptyLog())) {
208  ss << ' '; // 1 space for final empty names/values arrays
209  } else {
210  // All values are logged after all names, so separate values stream is needed.
211  std::stringstream values;
212  unsigned nvalues = 0;
213  if (query_state_ && !query_state_->getQueryStr().empty()) {
214  ss << (nvalues ? ',' : '{') << std::quoted("query_str", '"', '"');
215  values << (nvalues++ ? ',' : '{')
216  << std::quoted(hide_sensitive_data_from_query(query_state_->getQueryStr()),
217  '"',
218  '"');
219  }
220  for (auto itr = nv.cbegin(); itr != nv.cend(); ++itr) {
221  ss << (nvalues ? ',' : '{') << std::quoted(*itr, '"', '"');
222  values << (nvalues++ ? ',' : '{') << std::quoted(*++itr, '"', '"');
223  }
224  ss << "} " << values.rdbuf() << '}';
225  }
226  BOOST_LOG_SEV(logger::gSeverityLogger::get(), severity) << ss.rdbuf();
227  }
228 }
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
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:254
ThreadId thread_id()
Definition: Logger.cpp:731
+ Here is the call graph for this function:

◆ logCallStack()

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

Definition at line 230 of file QueryState.cpp.

References logger::fast_logging_check(), and query_state::Timer::query_state_.

230  {
231  if (logger::fast_logging_check(severity) && query_state_) {
232  std::stringstream ss;
233  ss << file_ << ':' << line_ << ' ' << label << ' ' << func_ << ' ' << match_
234  << " total time " << duration<std::chrono::milliseconds>() << " ms";
235  query_state_->logCallStack(ss);
236  BOOST_LOG_SEV(logger::gSeverityLogger::get(), severity) << ss.rdbuf();
237  }
238 }
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:

◆ setQueryState()

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

Definition at line 251 of file QueryState.cpp.

References query_state::Timer::query_state_.

Referenced by DBHandler::get_table_details_impl().

251  {
252  query_state_ = std::move(query_state);
253 }
std::shared_ptr< QueryState > query_state_
Definition: QueryState.h:254
+ Here is the caller graph for this function:

◆ setSessionInfo()

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

Definition at line 255 of file QueryState.cpp.

Referenced by DBHandler::connect_impl().

256  {
257  session_info_ = std::move(session_info);
258 }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryState.h:253
+ Here is the caller graph for this function:

◆ stdlogBeginSeverity()

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

Definition at line 169 of file QueryState.cpp.

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

169  {
170  logger::Severity const defaultSeverity = logger::Severity::DEBUG1;
171  static std::unordered_map<std::string_view, logger::Severity> const map{
172  {"connect", logger::Severity::INFO},
173  {"disconnect", logger::Severity::INFO},
174  {"switch_database", logger::Severity::INFO},
175  {"clone_session", logger::Severity::INFO},
176  {"get_tables_meta", logger::Severity::INFO},
177  {"get_table_details", logger::Severity::INFO},
178  {"sql_execute", logger::Severity::INFO},
179  {"sql_execute_df", logger::Severity::INFO},
180  {"sql_execute_gdf", logger::Severity::INFO},
181  {"sql_validate", logger::Severity::INFO},
182  {"render_vega", logger::Severity::INFO},
183  {"get_result_row_for_pixel", logger::Severity::INFO},
184  {"check_table_consistency", logger::Severity::INFO},
185  {"start_query", logger::Severity::INFO},
186  {"execute_query_step", logger::Severity::INFO},
187  {"broadcast_serialized_rows", logger::Severity::INFO},
188  {"start_render_query", logger::Severity::INFO},
189  {"execute_next_render_step", logger::Severity::INFO}};
190  auto const itr = map.find(func);
191  return itr == map.cend() ? defaultSeverity : itr->second;
192 }
Severity
Definition: Logger.h:73

Member Data Documentation

◆ query_state_

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

Definition at line 254 of file QueryState.h.

◆ session_info_

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

Definition at line 253 of file QueryState.h.


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