I like the sink idea, but I think that a log that has an ostream interface has several distinct advantages, and also if there are to be different levels of log (eg. warning,error) it is the only way that I feel cleanly handles the problem.
Log provides an interface to the stringstream member (mStream), it can provide other interfaces such as warning()
(i'll put the pre tag here just in case)
<pre>
ostream& error()
{
string str = mStream.str();
if(str.length())
{
for each sink:
sink.error(str);
mStream.str("");
}
return stream;
}
</pre>
The problem here (as I mentioned earlier) is that the error is not actually output until the next error is called. (The last error is output by the destructor.)
I've been trying to think of a solution, but I haven't been able to come up with anything workable. To me providing a flush() would be acceptable, so that the code that writes the buffer to the sinks could be done in flush, and if the user needed a log to be updated (mainly if it were a cerr/cout log, since fstreams aren't written to disk until they are closed or ofstream::flush is called).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I like the sink idea, but I think that a log that has an ostream interface has several distinct advantages, and also if there are to be different levels of log (eg. warning,error) it is the only way that I feel cleanly handles the problem.
Log provides an interface to the stringstream member (mStream), it can provide other interfaces such as warning()
(i'll put the pre tag here just in case)
<pre>
ostream& error()
{
string str = mStream.str();
if(str.length())
{
for each sink:
sink.error(str);
mStream.str("");
}
return stream;
}
</pre>
The problem here (as I mentioned earlier) is that the error is not actually output until the next error is called. (The last error is output by the destructor.)
I've been trying to think of a solution, but I haven't been able to come up with anything workable. To me providing a flush() would be acceptable, so that the code that writes the buffer to the sinks could be done in flush, and if the user needed a log to be updated (mainly if it were a cerr/cout log, since fstreams aren't written to disk until they are closed or ofstream::flush is called).