1
This commit is contained in:
parent
c866e95bdf
commit
ca263c4fa5
96
cpp/tglog.cc
96
cpp/tglog.cc
@ -97,45 +97,22 @@ namespace f8
|
||||
void TGLog::AddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr,
|
||||
int logclass1, int logclass2, a8::XObject* prop)
|
||||
{
|
||||
std::string logtime_str;
|
||||
{
|
||||
time_t nowtime = time(nullptr);
|
||||
struct tm tm_time = {0};
|
||||
localtime_r(&nowtime, &tm_time);
|
||||
std::string event_name = a8::Format("event_%d_%d", {logclass1, logclass2});
|
||||
InternalAddTrackLog(game_id,
|
||||
accountid,
|
||||
ip_saddr,
|
||||
event_name,
|
||||
prop);
|
||||
}
|
||||
|
||||
char buff[256];
|
||||
strftime(buff, a8::ArraySize(buff), "%F %T", &tm_time);
|
||||
logtime_str.append((char*)buff);
|
||||
}
|
||||
a8::MutableXObject* xobj = a8::MutableXObject::NewObject();
|
||||
|
||||
xobj->SetVal("#account_id", accountid);
|
||||
xobj->SetVal("#type", "track");
|
||||
xobj->SetVal("#time", logtime_str);
|
||||
xobj->SetVal("#ip", a8::GetIpAddress(ip_saddr));
|
||||
xobj->SetVal("#event_name", a8::Format("event_%d_%d", {logclass1, logclass2}));
|
||||
|
||||
xobj->SetVal("properties", *prop);
|
||||
void TGLog::AddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr,
|
||||
const std::string& event_name, a8::XObject* prop)
|
||||
{
|
||||
TGLogMsgNode *p = new TGLogMsgNode();
|
||||
p->game_id = game_id;
|
||||
xobj->ToJsonStr(p->jsonstr);
|
||||
impl_->msg_mutex.lock();
|
||||
if (impl_->bot_node) {
|
||||
impl_->bot_node->next = p;
|
||||
impl_->bot_node = p;
|
||||
} else {
|
||||
impl_->top_node = p;
|
||||
impl_->bot_node = p;
|
||||
}
|
||||
impl_->msg_mutex.unlock();
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(*impl_->save_cond_mutex);
|
||||
impl_->save_cond->notify_all();
|
||||
}
|
||||
}
|
||||
delete xobj;
|
||||
xobj = nullptr;
|
||||
InternalAddTrackLog(game_id,
|
||||
accountid,
|
||||
ip_saddr,
|
||||
event_name,
|
||||
prop);
|
||||
}
|
||||
|
||||
void TGLog::SaveToFileThreadProc()
|
||||
@ -202,4 +179,49 @@ namespace f8
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TGLog::InternalAddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr,
|
||||
const std::string& event_name, a8::XObject* prop)
|
||||
{
|
||||
std::string logtime_str;
|
||||
{
|
||||
time_t nowtime = time(nullptr);
|
||||
struct tm tm_time = {0};
|
||||
localtime_r(&nowtime, &tm_time);
|
||||
|
||||
char buff[256];
|
||||
strftime(buff, a8::ArraySize(buff), "%F %T", &tm_time);
|
||||
logtime_str.append((char*)buff);
|
||||
}
|
||||
a8::MutableXObject* xobj = a8::MutableXObject::NewObject();
|
||||
|
||||
xobj->SetVal("#account_id", accountid);
|
||||
xobj->SetVal("#type", "track");
|
||||
xobj->SetVal("#time", logtime_str);
|
||||
xobj->SetVal("#ip", a8::GetIpAddress(ip_saddr));
|
||||
xobj->SetVal("#event_name", event_name);
|
||||
|
||||
xobj->SetVal("properties", *prop);
|
||||
{
|
||||
TGLogMsgNode *p = new TGLogMsgNode();
|
||||
p->game_id = game_id;
|
||||
xobj->ToJsonStr(p->jsonstr);
|
||||
impl_->msg_mutex.lock();
|
||||
if (impl_->bot_node) {
|
||||
impl_->bot_node->next = p;
|
||||
impl_->bot_node = p;
|
||||
} else {
|
||||
impl_->top_node = p;
|
||||
impl_->bot_node = p;
|
||||
}
|
||||
impl_->msg_mutex.unlock();
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(*impl_->save_cond_mutex);
|
||||
impl_->save_cond->notify_all();
|
||||
}
|
||||
}
|
||||
delete xobj;
|
||||
xobj = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,9 +16,13 @@ namespace f8
|
||||
void SetProjectInfo(const std::string& project_name, bool is_poly_log);
|
||||
void AddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr,
|
||||
int logclass1, int logclass2, a8::XObject* prop);
|
||||
void AddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr,
|
||||
const std::string& event_name, a8::XObject* prop);
|
||||
|
||||
private:
|
||||
void SaveToFileThreadProc();
|
||||
void InternalAddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr,
|
||||
const std::string& event_name, a8::XObject* prop);
|
||||
|
||||
private:
|
||||
std::string project_name_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user