Teamcenter C++ API Reference  2312
FileAppender.hxx
Go to the documentation of this file.
1 // Copyright 2022 Siemens Digital Industries Software
2 // ==================================================
3 // Copyright 2022.
4 // Siemens Product Lifecycle Management Software Inc.
5 // All Rights Reserved.
6 // ==================================================
7 // Copyright 2022 Siemens Digital Industries Software
8 
9 #ifndef TEAMCENTER_COMMON_LOGGING_FILEAPPENDER_HXX
10 #define TEAMCENTER_COMMON_LOGGING_FILEAPPENDER_HXX
11 
12 #include <tclogging/Appender.hxx>
13 
14 #include <string>
15 #include <fstream>
16 
17 #include <sys/stat.h>
18 #include <time.h>
19 #include <sstream>
20 #include <iostream>
21 #include <regex>
22 #include <vector>
23 #include <cstdio>
24 
25 #ifdef _WIN32
26 #include <windows.h>
27 #else
28 #include <dirent.h>
29 #endif
30 
31 #include <tclogging/libtclogging_exports.h>
32 
33 namespace Teamcenter::Common::Logging
34 {
35 
36 
43  class TCLOGGING_API FileAppender : public Appender
44  {
45  public:
46 
56  static Appender* create( const std::string& relativeFolder, const std::string& baseFileName, int backups );
57  static Appender* create( FILE * fp );
58 
59  virtual ~FileAppender();
60  FileAppender() = delete;
61  FileAppender( const FileAppender& ) = delete;
62  FileAppender( FileAppender&& ) = delete;
63  FileAppender& operator=( const FileAppender& ) = delete;
64  FileAppender& operator=( FileAppender&& ) = delete;
65  private:
66  FileAppender( const std::string& relativeFolder, const std::string& baseFileName, int backups );
67  FileAppender( FILE* fptr );
68  public:
69 
70  virtual std::string getAbsoluteFilePath();
71 
72  private:
73  static std::string getCurrentDate();
74  static std::string formAbsoluteFilePath( const std::string& relativeFolder, const std::string& baseFileName );
75  void removeOldBackUp( const std::string& relativeFolder, const std::string& baseFileName, int backups );
76  static std::string getLogFolder( const std::string& relativeFolder );
77 
78  std::string filePath;
79  };
80 
81 }
82 
83 #include <tclogging/libtclogging_undef.h>
84 #endif