|
From: <or...@vp...> - 2004-02-23 19:40:31
|
David McKen wrote:
> I am looking to creating my own C++ stream class.
>=20
> For now all I want to do is overload the << operator so I can send
> data to a file and the screen, this is to try to prevent:
>=20
> cout << x;
> log_file << x;
>=20
> Essentially I want to do something like:
> my_stream log_out("log.txt");
> log_out << x; //Sends to both screen & log.txt.
>=20
> Wrapping this in a function is not exactly the best solution as I
> lose the ability to use the manipulators or I would have to fall back
> to using variable argument lists and sprintf().
>=20
> Does any one know a tutorial or book that could help me?
Not exactly a tutorial, but NeoEngine has it's own logging system, which=20
is exactly the same, what you would like to do. Download=20
neoengine-0.7.0.tar.bz2 from it's website:
http://neoengine.sourceforge.net/index.oldsite.php
and look at the LogSink classes. They use (guess what :) log sinks. You=20
attach sinks to the logger, and it writes to those sinks, which are=20
attached (log file, dos console, etc.). It uses the << operator. It also=20
has different log levels (info, warning, error, debug, etc.).
Though it is a small part of the 3D engine, yet I think it is powerful,=20
and easy to "detach" from the rest of the engine, as it is independent=20
from the engine. It is even separately stored in logstream.cpp and=20
logstream.h
Look at the first and second tutorials on the neoengine website (1.=20
Init&Exit, 2. RenderPolygon), as they mention how to use the logging=20
system. Just disregard the 3D stuff.
Hope that helps.
--
Greetings,
Bal=E1zs
|