Commit 864720a4 authored by Vadim Zeitlin's avatar Vadim Zeitlin Committed by Ronan

Document logging with session::set_logger()

Add description of the more flexible logging mechanism also available
now, in addition to basic logging.
parent 6d6fc7d3
# Logging
SOCI provides a very basic logging facility.
SOCI provides a flexible, but requiring some effort to use, way to log all
queries done by the library and a more limited but very simple way to do it.
## Simple logging
The following members of the `session` class support the basic logging functionality:
......@@ -24,3 +27,34 @@ Each statement logs its query string before the preparation step (whether explic
Note that each prepared query is logged only once, independent on how many times it is executed.
The `get_last_query` function allows to retrieve the last used query.
## Flexible logging using custom loggers
If the above is not enough, it is also possible to log the queries in exactly
the way you want by deriving your own `my_log_impl` class from
`soci::logger_impl` and implementing its pure virtual `start_query()` and
`do_clone()` methods:
class my_log_impl : public soci::logger_impl
virtual void start_query(std::string const & query)
... log the given query ...
virtual logger_impl* do_clone() const
return new my_log_impl(...);
Then simply pass a new, heap-allocated instance of this class to the `session`
soci::session sql(...);
sql.set_logger(new my_log_impl(...));
and `start_query()` method of the logger will be called for all queries.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment