diff --git a/example/2023-05-21.log b/example/2023-05-21.log new file mode 100644 index 0000000..0946989 --- /dev/null +++ b/example/2023-05-21.log @@ -0,0 +1 @@ +23:08:58 [EVENT] Start loging diff --git a/example/2023-5-21.log b/example/2023-5-21.log index 9999c2f..180c471 100644 --- a/example/2023-5-21.log +++ b/example/2023-5-21.log @@ -1 +1,2 @@ 11:00:58 [EVENT] Start loging +13:02:17 [EVENT] Start loging diff --git a/src/log.cpp b/src/log.cpp index 498aa5e..717fcb2 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -82,7 +82,11 @@ void log::setPath() { if (dir[dir.length()-1] != '/') { dir.push_back('/'); } - path = dir + to_string(moment->tm_year+1900) + '-' + to_string(moment->tm_mon+1) + '-' + to_string(moment->tm_mday) + ".log"; + + stringstream mon, _day; + mon << setw(2) << setfill('0') << moment->tm_mon+1; + _day << setw(2) << setfill('0') << moment->tm_mday; + path = dir + to_string(moment->tm_year+1900) + '-' + mon.str() + '-' + _day.str() + ".log"; } void log::setPrefix(string &logline) { diff --git a/test/test.cpp b/test/test.cpp index a955d42..15252c8 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -3,12 +3,13 @@ #include "../lib/log.hpp" using namespace std; +log mylog("../example", false); int main() { - log mylog("../example", false); +// log mylog("../example", false); mylog.put("[EVENT] Start loging"); return 0; -} \ No newline at end of file +} diff --git a/test/test.o b/test/test.o index a824953..98e93dd 100755 Binary files a/test/test.o and b/test/test.o differ