Hi All,
Resolving an issue with the Android build Gareth has to add AndroidLogLib to deal with the __android_log_print() usage that was originally used to workaround Android sending all cout and cerr messages to /dev/null. Rather than just added these new dependency to the core VSG for just a bit of debug output used in a single file I've decided to do a quick experiment with adding some logging functionality to the VSG.
My first step in this experiment has to been to create a Logging branch of vsgExamples:
This also inspired a previous suggestion from Sam Brkopac for having such functionality in the core VSG during the discussion about VulkanSceneGraph-1.0 work. Sam has used spdlog in his own projects so suggested that as possible reference. The LOC count for spdlog is half the size of the whole VSG project which is pretty crazy, so I'm not about to pull it into core VSG.
My vsglog.cpp example is just 168 lines of code, and already has a base Logger class, a thread safe StdLogger implementation that directs to std::cout and std::cerr, and CustomLogger implementation. Usage looks like:
vsg::info("info string");
vsg::warn("warn string");
vsg::critical("critical string");
vsg::error("error string");
vsg::info("time ", 10, "ms, vector = (", vsg::vec3(10.0f, 20.0f, 30.0f), ")");
vsg::log() = CustomLogger::create();
vsg::info("info string");
vsg::warn("warn string");
vsg::critical("critical string");
vsg::error("error string");
vsg::error("here ", std::string("and"), " matrix = {",vsg::dmat4{}, "}");
Output from this is:
$ vsglog
cout: info string
cout: warn string
cerr: critical string
cerr: error string
cout: info : time 10ms, vector = (10 20 30)
custom cout: info string
custom cout: warn string
custom cerr: critical string
custom cerr: error string
custom cout: error : here and matrix = {
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
}
The lines in form of:
vsg::info("time ", 10, "ms, vector = (", vsg::vec3(10.0f, 20.0f, 30.0f), ")");
Are handled by a template that uses a std::ostringstream that is created and destroyed on each invocation of the template function, so while it's super flexible it's far from efficient.
I will have a think whether I can reuse a ostringstream implementation per thread to avoid creating an destroying the ostringstream objects. Stuff like this will make the code rather more complicated...
I could just go with really basic and inefficient solution for 1.0, then come back to it. The question now me is how much functionality to build in right now. I'm open to suggestions about how to tackle this/what you'd like to see.
Cheers,
Robert.