8 #ifdef LOG4CPP_HAVE_IO_H 11 #ifdef LOG4CPP_HAVE_UNISTD_H 15 #include <sys/types.h> 27 #ifdef LOG4CPP_HAVE_SSTREAM 32 #ifndef WIN32 // only available on Win32 41 const std::string& fileName,
42 unsigned int maxDaysToKeep,
46 _maxDaysToKeep(maxDaysToKeep != 0 ? maxDaysToKeep : maxDaysToKeepDefault) {
52 res = ::stat(fileName.c_str(), &statBuf);
58 #ifndef WIN32 // only available on Win32 78 << std::setfill(
'0') << std::setw(2) <<
_logsTime.tm_mon + 1 <<
"-" 79 << std::setw(2) <<
_logsTime.tm_mday << std::ends;
80 const std::string lastFn = filename_s.
str();
81 ::rename(
_fileName.c_str(), lastFn.c_str());
88 #define PATHDELIMITER "/" 90 #define PATHDELIMITER "\\" 94 const std::string dirname((last_delimiter == std::string::npos)?
"." :
_fileName.substr(0, last_delimiter));
95 const std::string filname((last_delimiter == std::string::npos)?
_fileName :
_fileName.substr(last_delimiter+1,
_fileName.size()-last_delimiter-1));
96 #ifndef WIN32 // only available on Win32 97 struct dirent **entries;
98 int nentries = scandir(dirname.c_str(), &entries, 0, alphasort);
101 for (
int i = 0; i < nentries; i++) {
103 int res = ::stat(entries[i]->d_name, &statBuf);
104 if ((res == -1) || (!S_ISREG(statBuf.st_mode))) {
108 if (statBuf.st_mtime < oldest && strstr(entries[i]->d_name, filname.c_str())) {
109 const std::string fullfilename = dirname +
PATHDELIMITER + entries[i]->d_name;
110 ::unlink(fullfilename.c_str());
111 std::cout <<
" Deleting " << fullfilename.c_str() << std::endl;
117 HANDLE hFind = INVALID_HANDLE_VALUE;
119 const std::string pattern =
_fileName +
"*";
121 hFind = FindFirstFile(pattern.c_str(), &ffd);
122 if (hFind != INVALID_HANDLE_VALUE) {
125 const std::string fullfilename = dirname +
PATHDELIMITER + ffd.cFileName;
126 int res = ::stat(fullfilename.c_str(), &statBuf);
127 if (res != -1 && statBuf.st_mtime < oldest && !(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
128 std::cout <<
"Deleting " << fullfilename <<
"\n";
129 ::unlink(fullfilename.c_str());
131 }
while (FindNextFile(hFind, &ffd) != 0);
133 if (GetLastError() != ERROR_NO_MORE_FILES) {
137 hFind = INVALID_HANDLE_VALUE;
145 time_t t = time(NULL);
147 #ifndef WIN32 // only available on Win32 148 bool timeok = localtime_r(&t, &now) != NULL;
150 bool timeok = localtime_s(&now, &t) == 0;
153 if ((now.tm_mday !=
_logsTime.tm_mday) ||
165 std::string name, filename;
168 unsigned int max_days_keep = 0;
169 params.
get_for(
"daily roll file appender").
required(
"name", name)(
"filename", filename)(
"max_days_keep", max_days_keep)
170 .
optional(
"append", append)(
"mode", mode);
virtual unsigned int getMaxDaysToKeep() const
unsigned int _maxDaysToKeep
const std::string _fileName
virtual void _append(const LoggingEvent &event)
virtual void setMaxDaysToKeep(unsigned int maxDaysToKeep)
required_params_validator required(const char *param, T &value) const
DailyRollingFileAppender(const std::string &name, const std::string &fileName, unsigned int maxDaysToKeep=maxDaysToKeepDefault, bool append=true, mode_t mode=00644)
virtual void _append(const LoggingEvent &event)
static unsigned int maxDaysToKeepDefault
details::parameter_validator get_for(const char *tag) const
optional_params_validator optional(const char *param, T &value) const
std::auto_ptr< Appender > create_daily_roll_file_appender(const FactoryParams &)