Warning, /sdk/codevis/thirdparty/soci/docs/logging.md is written in an unsupported language. File is not indexed.
0001 # Logging
0002
0003 SOCI provides a flexible, but requiring some effort to use, way to log all
0004 queries done by the library and a more limited but very simple way to do it.
0005
0006 ## Simple logging
0007
0008 The following members of the `session` class support the basic logging functionality:
0009
0010 * `void set_log_stream(std::ostream * s);`
0011 * `std::ostream * get_log_stream() const;`
0012 * `std::string get_last_query() const;`
0013
0014 The first two functions allow to set the user-provided output stream object for logging.
0015 The `NULL` value, which is the default, means that there is no logging.
0016
0017 An example use might be:
0018
0019 session sql(oracle, "...");
0020
0021 ofstream file("my_log.txt");
0022 sql.set_log_stream(&file);
0023
0024 // ...
0025
0026 Each statement logs its query string before the preparation step (whether explicit or implicit) and therefore logging is effective whether the query succeeds or not.
0027 Note that each prepared query is logged only once, independent on how many times it is executed.
0028
0029 The `get_last_query` function allows to retrieve the last used query.
0030
0031 ## Flexible logging using custom loggers
0032
0033 If the above is not enough, it is also possible to log the queries in exactly
0034 the way you want by deriving your own `my_log_impl` class from
0035 `soci::logger_impl` and implementing its pure virtual `start_query()` and
0036 `do_clone()` methods:
0037
0038 class my_log_impl : public soci::logger_impl
0039 {
0040 public:
0041 virtual void start_query(std::string const & query)
0042 {
0043 ... log the given query ...
0044 }
0045
0046 private:
0047 virtual logger_impl* do_clone() const
0048 {
0049 return new my_log_impl(...);
0050 }
0051 };
0052
0053 Then simply pass a new, heap-allocated instance of this class to the `session`
0054 object:
0055
0056 soci::session sql(...);
0057 sql.set_logger(new my_log_impl(...));
0058
0059 and `start_query()` method of the logger will be called for all queries.