chenshuo / muduo

Event-driven network library for multi-threaded Linux server in C++11
https://github.com/chenshuo/muduo
Other
14.64k stars 5.14k forks source link

日志时间与系统时间不一致是什么原因呢?其它程序可以获取到正确时间,相差8小时 #621

Closed xs-411 closed 2 years ago

xs-411 commented 2 years ago

int main(const int argc, const char* argv[]) { for (int i = 0; i < 10; ++i) { LOG_INFO << 123; } return 0; } root@hecs-8a9e:/data/data/bin# date Wed 20 Jul 2022 10:18:01 PM CST root@hecs-8a9e:/data/data/bin# ./ChatServer 20220720 14:18:07.208419Z 104867 INFO 1658326687 - main.cpp:11 20220720 14:18:07.208465Z 104867 INFO 1658326687 - main.cpp:11 20220720 14:18:07.208466Z 104867 INFO 1658326687 - main.cpp:11 20220720 14:18:07.208467Z 104867 INFO 1658326687 - main.cpp:11 20220720 14:18:07.208468Z 104867 INFO 1658326687 - main.cpp:11 20220720 14:18:07.208470Z 104867 INFO 1658326687 - main.cpp:11 20220720 14:18:07.208471Z 104867 INFO 1658326687 - main.cpp:11 20220720 14:18:07.208472Z 104867 INFO 1658326687 - main.cpp:11 20220720 14:18:07.208473Z 104867 INFO 1658326687 - main.cpp:11 20220720 14:18:07.208474Z 104867 INFO 1658326687 - main.cpp:11

chenshuo commented 2 years ago

By default, muduo logging use UTC timestamp. You can change it by calling Logger::setTimeZone(const TimeZone& tz)

int main()
{
  // ...
  TimeZone chinaTime(8 * 3600, "CST");
  Logger::setTimeZone(chinaTime);
  // ...