A
AJG
Hi there. I am using a library called SOCI that has a method to set a
stream which it uses to log SQL queries. The signature is as follows:
void setLogStream(std:stream *s);
This works great when used with something like
setLogStream(&std::cerr). However, I would like to add more context to
the query logged. Specifically, I'd like to add the thread ID. So,
instead of the query logged looking like:
select * from foo;
it would look like:
<thread-id>| select * from foo;
I already have the function to get the thread id
(boost::this_thread::get_id()), but I need to find a way to pass an
object to setLogStream that will do the formatting for me. As far as I
can tell, the only way to do this is inheriting from std:stream and
somehow overriding the default formatting. Except I'm not sure which
of its methods are virtual and meant to be overridden. Any clues?
Basically, I figure what I need might look something like:
struct ThreadLogger : public std:stream {
// ...
virtual void someOverridenFunction(const char *const buffer) {
std::cerr << boost::this_thread::get_id() << "| " << buffer;
}
// ...
};
and then:
ThreadLogger logger;
setLogStream(&logger);
Is what I'm looking to do possible? Should I look into IO manipulators
instead? Any help greatly appreciated .
Thanks!
stream which it uses to log SQL queries. The signature is as follows:
void setLogStream(std:stream *s);
This works great when used with something like
setLogStream(&std::cerr). However, I would like to add more context to
the query logged. Specifically, I'd like to add the thread ID. So,
instead of the query logged looking like:
select * from foo;
it would look like:
<thread-id>| select * from foo;
I already have the function to get the thread id
(boost::this_thread::get_id()), but I need to find a way to pass an
object to setLogStream that will do the formatting for me. As far as I
can tell, the only way to do this is inheriting from std:stream and
somehow overriding the default formatting. Except I'm not sure which
of its methods are virtual and meant to be overridden. Any clues?
Basically, I figure what I need might look something like:
struct ThreadLogger : public std:stream {
// ...
virtual void someOverridenFunction(const char *const buffer) {
std::cerr << boost::this_thread::get_id() << "| " << buffer;
}
// ...
};
and then:
ThreadLogger logger;
setLogStream(&logger);
Is what I'm looking to do possible? Should I look into IO manipulators
instead? Any help greatly appreciated .
Thanks!