SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLImporter.cpp
Go to the documentation of this file.
1 /**
2  * \file SLImporter.cpp
3  * \authors Marcus Hudritsch
4  * \date July 2014
5  * \authors Marcus Hudritsch
6  * \copyright http://opensource.org/licenses/GPL-3.0
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9 */
10 
11 #include <SLImporter.h>
12 #include <cstdarg> // only needed because we wrap printf in logMessage, read the todo and fix it!
13 
14 //-----------------------------------------------------------------------------
15 /*! Default constructor, doesn't log anything
16  */
18  : _logConsoleVerbosity(LV_quiet),
19  _logFileVerbosity(LV_quiet),
20  _sceneRoot(nullptr),
21  _skeleton(nullptr)
22 {
23 }
24 //-----------------------------------------------------------------------------
25 /*! Constructor that only outputs console logs
26  */
28  : _logConsoleVerbosity(consoleVerb),
29  _logFileVerbosity(LV_quiet),
30  _sceneRoot(nullptr),
31  _skeleton(nullptr)
32 {
33 }
34 //-----------------------------------------------------------------------------
35 /*! Constructor that allows logging to a file with different verbosity
36  */
38  SLLogVerbosity logConsoleVerb,
39  SLLogVerbosity logFileVerb)
40  : _logConsoleVerbosity(logConsoleVerb),
41  _logFileVerbosity(logFileVerb),
42  _sceneRoot(nullptr),
43  _skeleton(nullptr)
44 {
46  _log.open(logFile.c_str());
47 }
48 //-----------------------------------------------------------------------------
49 /*! Destructor, closes the file stream if it was used
50  */
52 {
53  if (_log.is_open())
54  _log.close();
55 }
56 //-----------------------------------------------------------------------------
57 /*! Logs messages to the importer logfile and the console
58  @param msg the message to add to the log
59  @param verbosity the verbosity of the message
60  @todo Build a dedicated log class that can be instantiated (so the importer can have its own)
61  Let this log class write to file etc.
62  Don't use printf anymore, its c. (c++11 has to_str, else we have to work with ss (ugh...))
63  I only used printf here because it allows me to combine a string with different variables
64  in only one line and I don't have an easy way to do this in c++0x. Again c++11 would be easy.
65 */
66 void SLImporter::logMessage(SLLogVerbosity verbosity, const char* msg, ...)
67 {
68 #if defined(SL_OS_ANDROID)
69  SL_LOG(msg) ;
70 #else
71  // write message to a buffer
72  char buffer[4096];
73  std::va_list arg;
74  va_start(arg, msg);
75  std::vsnprintf(buffer, 4096, msg, arg);
76  va_end(arg);
77 
78  if (_logConsoleVerbosity >= verbosity)
79  SL_LOG("%s", buffer);
80  if (_logFileVerbosity >= verbosity)
81  {
82  _log << buffer;
83  _log.flush();
84  }
85 #endif
86 }
87 //-----------------------------------------------------------------------------
#define SL_LOG(...)
Definition: SL.h:233
string SLstring
Definition: SL.h:158
SLLogVerbosity
Definition: SLEnums.h:244
@ LV_quiet
Definition: SLEnums.h:245
SLLogVerbosity _logConsoleVerbosity
verbosity level of log output to the console
Definition: SLImporter.h:126
SLLogVerbosity _logFileVerbosity
verbosity level of log output to the file
Definition: SLImporter.h:127
virtual ~SLImporter()
Definition: SLImporter.cpp:51
void logMessage(SLLogVerbosity verbosity, const char *msg,...)
Definition: SLImporter.cpp:66
std::ofstream _log
log stream
Definition: SLImporter.h:124