-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Given an application that operates on many high level objects, it may be insightful to get to know what SQL queries are given within the scope of each object.
Current State
We have some loggers already, but maybe we need to clean up a bit:
- SqlScopedTraceLogger: scoped ODBC low level logger (unrelated to
SqlLogger) - SqlLogger: core logging API
- SqlNullLogger: specialization of
SqlLogger, not logging anything - SqlStandardLogger: creates standard log messages and prints them to stdout, ignores any SQL query logging, only warnings and errors are logged
- SqlTraceLogger: extends
SqlStandardLogger, also implementing query logging - SqlScopedTimeLogger: measures the time spend within the current scope and logs it to the current logger
Goals
What we need is an interface that groups the high level objects together and allows logging any of the SQL queries (or log messages) within that group as context.
NB: It makes sense to not just allow logging to stdout, but customize it.
The suggestion is to allow customizing where to write (see SqlStandardLogger::WriteMessage) and to allow passing a context, in form of a string tag, which could name the high level object to be processed.
/// mock up
void runAllComplexJob(auto& jobs)
{
for (auto& job: jobs)
{
runComplexJob(job);
}
}
void runComplexJobs(auto& job)
{
auto sqlContext = SqlScopedLoggingContext(job.title);
job.run();
for (auto const& message: sqlContext.Messages())
std::println("[{}] {}", sqlContext.Name(), message);
}
class SqlScopedLoggingContext
{
public:
explicit SqlScopedLoggingContext(std::string name);
~SqlScopedLoggingContext();
std::string const& Name();
std::vector<std::string> const& Messages();
};Reactions are currently unavailable