Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "PortabilityImpl.hh"
00008 #ifdef LOG4CPP_HAVE_IO_H
00009 # include <io.h>
00010 #endif
00011 #ifdef LOG4CPP_HAVE_UNISTD_H
00012 # include <unistd.h>
00013 #endif
00014
00015 #include <sys/types.h>
00016 #include <sys/stat.h>
00017 #include <fcntl.h>
00018 #include <log4cpp/GenerationalFileAppender.hh>
00019 #include <log4cpp/Category.hh>
00020 #include <log4cpp/FactoryParams.hh>
00021 #include <memory>
00022 #include <stdio.h>
00023
00024 #ifdef LOG4CPP_HAVE_SSTREAM
00025 #include <sstream>
00026 #endif
00027
00028 namespace log4cpp {
00029
00030 GenerationalFileAppender::GenerationalFileAppender(const std::string& name,
00031 const std::string& fileName,
00032 bool append,
00033 mode_t mode) :
00034 FileAppender(name, fileName+".0", append, mode),
00035 _originalFileName(fileName),
00036 _generation(0) {
00037 }
00038
00039 void GenerationalFileAppender::advanceGeneration() {
00040 ++_generation;
00041 std::ostringstream str;
00042 str << _originalFileName << "." << _generation << std::ends;
00043 int new_fd = ::open(str.str().c_str(), _flags, _mode);
00044 if (-1 != new_fd)
00045 {
00046
00047 int old_fd = _fd;
00048 _fd = new_fd;
00049 ::close(old_fd);
00050 }
00052 }
00053
00054 std::auto_ptr<Appender> create_generation_file_appender(const FactoryParams& params)
00055 {
00056 std::string name, filename;
00057 bool append = true;
00058 mode_t mode = 664;
00059 params.get_for("rool file appender").required("name", name)("filename", filename)
00060 .optional("append", append)("mode", mode);
00061
00062 return std::auto_ptr<Appender>(new GenerationalFileAppender(name, filename, append, mode));
00063 }
00064 }
log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Aug 14 2016 03:18:26