This commit is contained in:
aozhiwei 2022-11-09 10:56:40 +08:00
parent a82a78407b
commit 7cba21ca64
2 changed files with 17 additions and 4 deletions

View File

@ -1,4 +1,6 @@
#include <unistd.h> #include <unistd.h>
#include <sys/time.h>
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <condition_variable> #include <condition_variable>
@ -25,6 +27,7 @@ namespace f8
std::string filename_fmt; std::string filename_fmt;
std::string project_name; std::string project_name;
bool is_poly_log = false; bool is_poly_log = false;
int time_zone = 0;
std::thread* save_thread = nullptr; std::thread* save_thread = nullptr;
volatile bool save_thread_shutdown = false; volatile bool save_thread_shutdown = false;
@ -56,6 +59,12 @@ namespace f8
std::string GetCurrentFileName() std::string GetCurrentFileName()
{ {
time_t nowtime = time(nullptr); time_t nowtime = time(nullptr);
{
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
nowtime = tz.tz_minuteswest * -3600 + time_zone * 3600;
}
struct tm tm_nowtime = {0}; struct tm tm_nowtime = {0};
localtime_r(&nowtime, &tm_nowtime); localtime_r(&nowtime, &tm_nowtime);
@ -67,12 +76,14 @@ namespace f8
} }
}; };
void TGLog::Init(const std::string& project_name, bool is_poly_log) void TGLog::Init(const std::string& project_name, bool is_poly_log, int time_zone)
{ {
time_zone_ = time_zone;
project_name_ = project_name; project_name_ = project_name;
is_poly_log_ = is_poly_log; is_poly_log_ = is_poly_log;
impl_ = new TGLogImpl(); impl_ = new TGLogImpl();
impl_->filename_fmt = TGLOG_FILENAME; impl_->filename_fmt = TGLOG_FILENAME;
impl_->time_zone = time_zone;
a8::ReplaceString(impl_->filename_fmt, "$pid", a8::XValue(getpid())); a8::ReplaceString(impl_->filename_fmt, "$pid", a8::XValue(getpid()));
impl_->project_name = project_name_; impl_->project_name = project_name_;
@ -88,8 +99,9 @@ namespace f8
impl_ = nullptr; impl_ = nullptr;
} }
void TGLog::SetProjectInfo(const std::string& project_name, bool is_poly_log) void TGLog::SetProjectInfo(const std::string& project_name, bool is_poly_log, int time_zone)
{ {
time_zone_ = time_zone;
project_name_ = project_name; project_name_ = project_name;
is_poly_log_ = is_poly_log; is_poly_log_ = is_poly_log;
} }

View File

@ -10,10 +10,10 @@ namespace f8
friend class a8::Singleton<TGLog>; friend class a8::Singleton<TGLog>;
public: public:
void Init(const std::string& project_name, bool is_poly_log); void Init(const std::string& project_name, bool is_poly_log, int time_zone = 8);
void UnInit(); void UnInit();
void SetProjectInfo(const std::string& project_name, bool is_poly_log); void SetProjectInfo(const std::string& project_name, bool is_poly_log, int time_zone = 8);
void AddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr, void AddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr,
int logclass1, int logclass2, a8::XObject* prop); int logclass1, int logclass2, a8::XObject* prop);
void AddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr, void AddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr,
@ -25,6 +25,7 @@ namespace f8
const std::string& event_name, a8::XObject* prop); const std::string& event_name, a8::XObject* prop);
private: private:
int time_zone_ = 0;
std::string project_name_; std::string project_name_;
bool is_poly_log_ = false; bool is_poly_log_ = false;
TGLogImpl* impl_ = nullptr; TGLogImpl* impl_ = nullptr;