CoCoALib offers its own "log output stream" for logging messages
(see for instance obsolescent
. By default this is std::cout
but it may be set to any other stream (_e.g._ std::clog
).
NOTE: internally the implementation uses a global variable, so multi-threaded
applications should be careful about using LogStreamForThisBlock
.
LogStream()
returns the current CoCoA "log stream" (as a ref to std::ostream
)
LogStreamForThisBlock BlockName(out)
sets the CoCoA "log stream" (global var) to be out
(of type std::ostream
) for this code block; it restores previous stream upon exiting the block.
The implementation could hardly be simpler.
The global variable is a pointer because references cannot be reseated in C++
(so it would be impossible to implement mySetLogStreamPtr
).
Should the default CoCoA "log stream" be std::cout
or std::clog
?
std::cout
is probably easier to deal with for non-expert users
(_e.g._ when redirecting output to a file).
2017