TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::Log Class Reference

#include <Log.h>

Public Member Functions

 Log (const std::string &filename="log.txt", int stripFromStackBottom=0)
 
virtual ~Log ()
 
FILE * getFile () const
 
void section (const std::string &s)
 
void __cdecl printf (const char *fmt,...) G3D_CHECK_PRINTF_METHOD_ARGS
 
void __cdecl vprintf (const char *, va_list argPtr) G3D_CHECK_VPRINTF_METHOD_ARGS
 
void __cdecl lazyvprintf (const char *, va_list argPtr) G3D_CHECK_VPRINTF_METHOD_ARGS
 
void print (const std::string &s)
 
void println (const std::string &s)
 

Static Public Member Functions

static Logcommon ()
 
static std::string getCommonLogFilename ()
 

Public Attributes

int stripFromStackBottom
 

Private Attributes

FILE * logFile
 
std::string filename
 

Static Private Attributes

static LogcommonLog = NULL
 

Detailed Description

System log for debugging purposes. The first log opened is the "common log" and can be accessed with the static method common(). If you access common() and a common log does not yet exist, one is created for you.

Constructor & Destructor Documentation

Log::Log ( const std::string &  filename = "log.txt",
int  stripFromStackBottom = 0 
)
Parameters
stripFromStackBottomNumber of call stacks to strip from the bottom of the stack when printing a trace. Useful for hiding routines like "main" and "WinMain". If the specified file cannot be opened for some reason, tries to open "c:/tmp/log.txt" or "c:/temp/log.txt" instead.
42  :
44 
45  this->filename = filename;
46 
47  logFile = FileSystem::fopen(filename.c_str(), "w");
48 
49  if (logFile == NULL) {
50  std::string drive, base, ext;
51  Array<std::string> path;
52  parseFilename(filename, drive, path, base, ext);
53  std::string logName = base + ((ext != "") ? ("." + ext) : "");
54 
55  // Write time is greater than 1ms. This may be a network drive.... try another file.
56  #ifdef G3D_WINDOWS
57  logName = std::string(std::getenv("TEMP")) + logName;
58  #else
59  logName = std::string("/tmp/") + logName;
60  #endif
61 
62  logFile = FileSystem::fopen(logName.c_str(), "w");
63  }
64 
65  // Use a large buffer (although we flush in logPrintf)
66  setvbuf(logFile, NULL, _IOFBF, 2048);
67 
68  fprintf(logFile, "Application Log\n");
69  time_t t;
70  time(&t);
71  fprintf(logFile, "Start: %s\n", ctime(&t));
72  fflush(logFile);
73 
74  if (commonLog == NULL) {
75  commonLog = this;
76  }
77 }
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args)
arena_t NULL
Definition: jemalloc_internal.h:624
int stripFromStackBottom
Definition: Log.h:61
FILE * logFile
Definition: Log.h:54
static FILE * fopen(const char *filename, const char *mode)
Definition: FileSystem.h:282
static Log * commonLog
Definition: Log.h:58
void parseFilename(const std::string &filename, std::string &drive, Array< std::string > &path, std::string &base, std::string &ext)
Definition: fileutils.cpp:457
std::string filename
Definition: Log.h:56

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Log::~Log ( )
virtual
80  {
81  section("Shutdown");
82  println("Closing log file");
83 
84  // Make sure we don't leave a dangling pointer
85  if (Log::commonLog == this) {
87  }
88 
89  if (logFile) {
91  }
92 }
static void fclose(FILE *f)
Definition: FileSystem.h:290
arena_t NULL
Definition: jemalloc_internal.h:624
void section(const std::string &s)
Definition: Log.cpp:113
FILE * logFile
Definition: Log.h:54
static Log * commonLog
Definition: Log.h:58
void println(const std::string &s)
Definition: Log.cpp:144

+ Here is the call graph for this function:

Member Function Documentation

Log * Log::common ( )
static
100  {
101  if (commonLog == NULL) {
102  commonLog = new Log();
103  }
104  return commonLog;
105 }
arena_t NULL
Definition: jemalloc_internal.h:624
Log(const std::string &filename="log.txt", int stripFromStackBottom=0)
Definition: Log.cpp:42
static Log * commonLog
Definition: Log.h:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string Log::getCommonLogFilename ( )
static
108  {
109  return common()->filename;
110 }
static Log * common()
Definition: Log.cpp:100
std::string filename
Definition: Log.h:56

+ Here is the call graph for this function:

FILE * Log::getFile ( ) const

Returns the handle to the file log.

95  {
96  return logFile;
97 }
FILE * logFile
Definition: Log.h:54
void __cdecl Log::lazyvprintf ( const char *  fmt,
va_list  argPtr 
)

Does not flush

133  {
134  vfprintf(logFile, fmt, argPtr);
135 }
FILE * logFile
Definition: Log.h:54
Definition: format.h:285

+ Here is the caller graph for this function:

void Log::print ( const std::string &  s)
138  {
139  fprintf(logFile, "%s", s.c_str());
140  fflush(logFile);
141 }
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args)
FILE * logFile
Definition: Log.h:54

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void __cdecl Log::printf ( const char *  fmt,
  ... 
)

Given arguments like printf, writes characters to the debug text overlay.

119  {
120  va_list arg_list;
121  va_start(arg_list, fmt);
122  print(vformat(fmt, arg_list));
123  va_end(arg_list);
124 }
void print(const std::string &s)
Definition: Log.cpp:138
std::string vformat(const char *fmt, va_list argPtr) G3D_CHECK_VPRINTF_ARGS
Definition: format.cpp:122
Definition: format.h:285

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Log::println ( const std::string &  s)
144  {
145  fprintf(logFile, "%s\n", s.c_str());
146  fflush(logFile);
147 }
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args)
FILE * logFile
Definition: Log.h:54

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Log::section ( const std::string &  s)

Marks the beginning of a logfile section.

113  {
114  fprintf(logFile, "_____________________________________________________\n");
115  fprintf(logFile, "\n ### %s ###\n\n", s.c_str());
116 }
FMT_API int fprintf(std::FILE *f, CStringRef format, ArgList args)
FILE * logFile
Definition: Log.h:54

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void __cdecl Log::vprintf ( const char *  fmt,
va_list  argPtr 
)
127  {
128  vfprintf(logFile, fmt, argPtr);
129  fflush(logFile);
130 }
FILE * logFile
Definition: Log.h:54
Definition: format.h:285

+ Here is the caller graph for this function:

Member Data Documentation

Log * Log::commonLog = NULL
staticprivate
std::string G3D::Log::filename
private
FILE* G3D::Log::logFile
private

Log messages go here.

int G3D::Log::stripFromStackBottom

The documentation for this class was generated from the following files: