1
This commit is contained in:
parent
c866e95bdf
commit
ca263c4fa5
98
cpp/tglog.cc
98
cpp/tglog.cc
@ -97,45 +97,22 @@ namespace f8
|
|||||||
void TGLog::AddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr,
|
void TGLog::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)
|
||||||
{
|
{
|
||||||
std::string logtime_str;
|
std::string event_name = a8::Format("event_%d_%d", {logclass1, logclass2});
|
||||||
{
|
InternalAddTrackLog(game_id,
|
||||||
time_t nowtime = time(nullptr);
|
accountid,
|
||||||
struct tm tm_time = {0};
|
ip_saddr,
|
||||||
localtime_r(&nowtime, &tm_time);
|
event_name,
|
||||||
|
prop);
|
||||||
|
}
|
||||||
|
|
||||||
char buff[256];
|
void TGLog::AddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr,
|
||||||
strftime(buff, a8::ArraySize(buff), "%F %T", &tm_time);
|
const std::string& event_name, a8::XObject* prop)
|
||||||
logtime_str.append((char*)buff);
|
{
|
||||||
}
|
InternalAddTrackLog(game_id,
|
||||||
a8::MutableXObject* xobj = a8::MutableXObject::NewObject();
|
accountid,
|
||||||
|
ip_saddr,
|
||||||
xobj->SetVal("#account_id", accountid);
|
event_name,
|
||||||
xobj->SetVal("#type", "track");
|
prop);
|
||||||
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);
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TGLog::SaveToFileThreadProc()
|
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 SetProjectInfo(const std::string& project_name, bool is_poly_log);
|
||||||
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,
|
||||||
|
const std::string& event_name, a8::XObject* prop);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SaveToFileThreadProc();
|
void SaveToFileThreadProc();
|
||||||
|
void InternalAddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr,
|
||||||
|
const std::string& event_name, a8::XObject* prop);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string project_name_;
|
std::string project_name_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user