GteLogToFile.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
10 #include <fstream>
11 using namespace gte;
12 
13 
14 LogToFile::LogToFile(std::string const& filename, int flags)
15  :
16  Logger::Listener(flags),
17  mFilename(filename)
18 {
19  std::ofstream logFile(filename);
20  if (logFile)
21  {
22  // This clears the file contents from any previous runs.
23  logFile.close();
24  }
25  else
26  {
27  // The file cannot be opened. Use a null string for Report to know
28  // not to attempt opening the file for append.
29  mFilename = "";
30  }
31 }
32 
34 {
35  if (mFilename != "")
36  {
37  // Open for append.
38  std::ofstream logFile(mFilename,
39  std::ios_base::out | std::ios_base::app);
40  if (logFile)
41  {
42  logFile << message.c_str();
43  logFile.close();
44  }
45  else
46  {
47  // The file cannot be opened. Use a null string for Report not
48  // to attempt opening the file for append on the next call.
49  mFilename = "";
50  }
51  }
52 }
53 
std::string mFilename
Definition: GteLogToFile.h:23
virtual void Report(std::string const &message)
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2538
GLbitfield flags
Definition: glcorearb.h:1591
LogToFile(std::string const &filename, int flags)


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00