Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cLogFileDay.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cLogFileDay_H
7 #define _INC_cLogFileDay_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../GrayLibBase.h"
14 #include "GrayCore/include/cFile.h"
16 #include "GrayCore/include/cMime.h"
17 
18 namespace GrayLib
19 {
21  {
25 
26  public:
30 
31  private:
32  cStringF m_sFileBaseDir;
33  cStringF m_sFileNameFormat;
34  int m_iLastDayStamp;
35 
36  protected:
37  cStringF MakeLogPath(const FILECHAR_t* pszFileBaseDir, const FILECHAR_t* pszName) const;
38  HRESULT OpenLogNew(const cTimeUnits& rTu);
39  HRESULT OpenLogCheck(bool bStampLine);
40 
41  public:
42  cLogFileDay(const FILECHAR_t* pszFileFormat = _FN("log%s") _FN(MIME_EXT_log), int iLogKeepDays = 0);
43  virtual ~cLogFileDay();
44 
45  bool isLogOpen() const
46  {
47  return m_LogFile.isFileOpen();
48  }
50  {
52  return m_LogFile.get_FilePath();
53  }
54 
56  {
57  return m_sFileBaseDir;
58  }
59  HRESULT put_LogDir(cStringF sDir);
60  static cStringF GRAYCALL GetDefaultLogDir();
61 
62  void CloseLog();
63  HRESULT OpenLog();
64  void DeleteOldLogs();
65 
66  // write a log line.
67  virtual HRESULT WriteString(const LOGCHAR_t* pszMsg) override;
68 
69  virtual HRESULT FlushX() override
70  {
71  return m_LogFile.FlushX();
72  }
73  };
74 };
75 #endif
#define _FN(x)
like _T(x) macro for static text file names.
Definition: FileName.h:23
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define MIME_EXT_log
Definition: cMime.h:49
Definition: cLogFileDay.h:21
virtual HRESULT FlushX() override
Definition: cLogFileDay.h:69
cFile m_LogFile
Place new logged events here. text file.
Definition: cLogFileDay.h:27
cStringF get_LogDir() const
Definition: cLogFileDay.h:55
int m_iLogKeepDays
Only keep logs for this many days. then delete file. 0 = forever.
Definition: cLogFileDay.h:28
cStringF get_LogPath() const
Definition: cLogFileDay.h:49
bool isLogOpen() const
Definition: cLogFileDay.h:45
bool m_bLockOpenClose
Locked in the current OpenLogCheck or close state.
Definition: cLogFileDay.h:29
Definition: cFile.h:137
virtual HRESULT FlushX() override
Definition: cFile.cpp:608
cStringF get_FilePath() const
Definition: cFile.h:222
virtual bool isFileOpen() const
Definition: cFile.h:259
Definition: cStream.h:126
Definition: cTimeUnits.h:146
Definition: cMesh.h:22
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
char LOGCHAR_t
always just use UTF8 for logs, don't bother with UNICODE.
Definition: cLogLevel.h:17