This commit is contained in:
gabime 2014-01-27 13:20:00 +02:00
parent b10cfa8180
commit 3a30e57d25
3 changed files with 8 additions and 8 deletions

View File

@ -17,7 +17,6 @@ OUTLIB_DEBUG = libc11log-debug.a
TEST_RELEASE = testme TEST_RELEASE = testme
TEST_DEBUG = testme-debug TEST_DEBUG = testme-debug
.PHONY: all mkdirs release debug build clean .PHONY: all mkdirs release debug build clean
all: release all: release
@ -48,6 +47,6 @@ debug/%.o: $(SRC_DIR)/%.cpp
$(CXX) -c $< -o $@ $(CXXFLAGS) $(CXX) -c $< -o $@ $(CXXFLAGS)
clean: clean:
rm -rf release debug $(TEST_RELEASE) $(TEST_DEBUG) $(OUTLIB_RELEASE) $(OUTLIB_DEBUG) rm -rf release debug daily.* $(TEST_RELEASE) $(TEST_DEBUG) $(OUTLIB_RELEASE) $(OUTLIB_DEBUG)

View File

@ -109,15 +109,15 @@ private:
/* /*
* Thread safe file sink that closes the log file at midnight and opens new one * Thread safe file sink that closes the log file at midnight and opens new one
*/ */
class midnight_file_sink:public base_sink { class daily_file_sink:public base_sink {
public: public:
midnight_file_sink(const std::string& base_filename, const std::string& extension = "txt"): daily_file_sink(const std::string& base_filename, const std::string& extension = "txt"):
_base_filename(base_filename), _base_filename(base_filename),
_extension(extension), _extension(extension),
_midnight_tp { _calc_midnight_tp() } _midnight_tp { _calc_midnight_tp() }
{ {
_ofstream.open(_calc_filename(_base_filename, _extension)); _ofstream.open(_calc_filename(_base_filename, _extension), std::ofstream::app);
} }
protected: protected:

View File

@ -16,9 +16,9 @@ int main(int argc, char* argv[])
int nthreads = argc > 1 ? atoi(argv[1]) : 1; int nthreads = argc > 1 ? atoi(argv[1]) : 1;
auto null_sink = std::make_shared<c11log::sinks::null_sink>(); auto null_sink = std::make_shared<c11log::sinks::null_sink>();
auto stdout_sink = std::make_shared<c11log::sinks::stdout_sink>(); auto stdout_sink = std::make_shared<c11log::sinks::stdout_sink>();
auto async = std::make_shared<c11log::sinks::async_sink>(100); auto async = std::make_shared<c11log::sinks::async_sink>(1000);
//auto fsink = std::make_shared<c11log::sinks::rotating_file_sink>("newlog", "txt", 1024*1024*10 , 2); //auto fsink = std::make_shared<c11log::sinks::rotating_file_sink>("newlog", "txt", 1024*1024*10 , 2);
auto fsink = std::make_shared<c11log::sinks::midnight_file_sink>("midnight", "txt"); auto fsink = std::make_shared<c11log::sinks::daily_file_sink>("daily", "txt");
async->add_sink(fsink); async->add_sink(fsink);
@ -39,7 +39,8 @@ int main(int argc, char* argv[])
}); });
} }
while (true) int seconds = 0;
while (seconds++ < 5)
{ {
counter = 0; counter = 0;
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::seconds(1));