A simple c++ log class that uses stream semantics.
Copy picolog.hpp
into your projects include path. Done.
Either use the log
function to get a reference to a Log
instance using
std::cout
:
pico::log().d() << "This is message number " << 4 << std::endl;
Or create your own Log
using a different ostream
:
std::ofstream file;
file.open("test.txt");
pico::Log log(file);
log.d() << "This is a test" << std::endl;
// Don't forget to close the file when you are done with logging
file.close();
User types can easily be logged by overloading operator<<
:
pico::Log& operator<<(Log& log, const UserType& u)
{
return log << u.a << "," << u.b;
}
UserType u = { "test", 2.5f };
log().d() << "A user type: " << u << std::endl;
You can use the Makefile and type make all
or use a simple g++ command:
g++ -I. example.cpp -Wall -Wpedantic
picolog uses the zlib license that is shipped with the header file.