InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
LogObject.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: lance bushore
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //
23 // This file is conditionally compiled. If we are building Public, we want
24 // to only build this if we are doing a DEBUG build. If we are building
25 // TestLib, we want to build this if we are doing a non-DEBUG build. This
26 // is so that Logging code will be stripped out of shipping code, but still
27 // allow us to write logs from test plugins in non-debug builds.
28 //
29 //========================================================================================
30 
31 #ifndef __LogObject__
32 #define __LogObject__
33 
34 #include <time.h>
35 #include "IDFile.h"
36 #include "IPMStream.h" // for OpenMode
37 #include <string>
38 
39 #if defined (ID_ENABLE_DEBUGGING) && (!TESTLIB_BUILD)
40 #define LOG_DECL
41 #else
42 #define LOG_DECL TESTLIB_DECL
43 #endif
44 
45 class IXferBytes;
46 class IPMStream;
47 
48 //If you change the definition of LogObject, remember to build
49 //Public. Both TestLib and Public include LogObject.cpp, but
50 //this class belongs to Public in the Debug build. Building
51 //TestLib alone won't allow the linker to resolve a reference
52 //to, for example, an added member function.
53 
68 class LOG_DECL LogObject
69 {
70  public:
71 
82  LogObject(const char *logFileName, bool16 newFile = kTrue, bool16 writeMemoryInfo = kTrue, bool16 autoflush = kFalse);
83 
93  LogObject(bool16 newFile, const char *logFileName, bool16 autoflush = kFalse);// For those who do not want any header trailer text
94 
106  LogObject(IDFile pathAndName, bool16 newFile = kTrue, bool16 autoflush = kFalse);
107 
113  virtual ~LogObject();
114 
121  void WriteLog(bool16 terminateLine, const char *format, ... );
122 
129  void WriteLogFormat(const char *format, va_list argptr, bool16 terminateLine = kTrue );
130 
131 
137  void WriteLog(const PMString& logString, bool16 terminateLine = kTrue);
138 
139 
144  void WriteDateTime(bool16 terminateLine);
145 
146 
151  void WriteElapsedTime(bool16 terminateLine);
152 
157  void WriteMemoryInfo();
158 
162  void WriteAvailableMemory();
163 
167  void WriteMemoryUsed();
168 
172  void WriteSeparator();
173 
177  void Indent();
178 
182  void UnIndent();
183 
188  int16 GetNumIndents();
189 
190 
196  void Prepend(const PMString& prepend);
197 
201  void RemovePrepend();
202 
203 
208  void SetWriteTrailer(bool16 writeTrailer) { fWriteTrailer = writeTrailer; }
209 
215  static PMString GetQAFileDir();
216 
222  static PMString GetLogFileDir();
223 
230  static PMString GetBenchmarkDataDir();
231 
236  static PMString GetPortDirName();
237 
242  PMString GetLogFileName(void);
243 
244 
250  void WriteInsert(const PMString& logString, CharCounter startPos);
251 
256  void WriteBasicHeader(const char *fileName);
257 
258  protected:
259 
260  private:
261  IPMStream *GetStream( OpenMode mode = kOpenTrunc );
262  void CloseStream();
263 
264  time_t fStartTime;
265  int32 fStartMem;
266  IDFile fLogFile;
267  IPMStream *fLogStream;
268  IXferBytes *fXferBytes;
269  bool16 fWriteTrailer;
270  std::string fIndent;
271  std::string fPrepend;
272  bool16 fAutoflush;
273 };
274 #endif