Line data Source code
1 : #include <wlog/formatter/formatter.hpp>
2 : #include <wlog/writer/file_writer.hpp>
3 : #include <iostream>
4 : #include "test.hpp"
5 :
6 : namespace
7 : {
8 :
9 : static const time_t test_time = 1512672862;
10 : static wlog::time_point tp;
11 :
12 : int test1();
13 :
14 1 : int test1()
15 : {
16 : {
17 1 : wlog::file_writer::options opt;
18 1 : opt.startup_rotate = 1;
19 1 : opt.path = "./test4.log";
20 2 : wlog::formatter_options fo;
21 2 : wlog::formatter fmt(fo, wlog::formatter_handlers() );
22 2 : wlog::file_writer fw( fmt, opt);
23 1 : fw(tp, "TEST4", "MESSAGE", "test1\n");
24 2 : std::ifstream ifs("./test4.log");
25 2 : std::string testline;
26 1 : std::getline( ifs, testline);
27 1 : std::cout << "[" << testline << "]" << std::endl;
28 2 : TEST( testline == "2017-12-07 21:54:22 TEST4 MESSAGE test1" );
29 : }
30 :
31 : {
32 1 : wlog::file_writer::options opt;
33 1 : opt.startup_rotate = 1;
34 1 : opt.rotation = 1;
35 1 : opt.path = "./test4.log";
36 2 : wlog::formatter_options fo;
37 2 : wlog::formatter fmt(fo, wlog::formatter_handlers());
38 2 : wlog::file_writer fw( fmt, opt);
39 1 : fw(tp, "TEST4", "MESSAGE", "test1\n");
40 : {
41 1 : std::ifstream ifs("./test4.log.old-0");
42 2 : std::string testline;
43 1 : std::getline( ifs, testline);
44 1 : std::cout << "[" << testline << "]" << std::endl;
45 2 : TEST( testline == "2017-12-07 21:54:22 TEST4 MESSAGE test1" );
46 : }
47 :
48 : {
49 1 : std::ifstream ifs("./test4.log");
50 2 : std::string testline;
51 1 : std::getline( ifs, testline);
52 1 : std::cout << testline << std::endl;
53 2 : TEST( testline == "2017-12-07 21:54:22 TEST4 MESSAGE test1" );
54 1 : }
55 : }
56 1 : return 0;
57 : }
58 :
59 : }
60 :
61 1 : int main()
62 : {
63 1 : setenv("TZ", "MSK-3", 1);
64 1 : tzset();
65 1 : tp = wlog::time_point::clock::from_time_t(test_time);
66 1 : tp += std::chrono::microseconds(123456);
67 :
68 :
69 1 : if ( int res = test1() )
70 0 : return res;
71 1 : return 0;
72 3 : }
|