Application library
- As pictured below, using application libraries enables to transfer of logs to the log collect server.
Examples¶
Note
For more samples of other languages, go to Hive Console > Analytics > Log Definition. Details
// https://github.com/fluent/fluent-logger-java
package com.hive.sample;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import org.fluentd.logger.FluentLogger;
public class GameLogAPI {
private static FluentLogger LOG = FluentLogger.getLogger("ha2union.gameserver.java");
public static void log_hive_login_log(String ageGate13, String changeUid, String thirdPartyAssent, String tag1, String hiveNewUser, String timezone, String channel, String source, String serverId, String osVer, long vid, long uid, String appId, String company, String model, String lang, String class, String os, String appVer, String cpu, String market, String clientIp, String sdkVer, String serverIp, long did, String grouping, String newUser, String guestUser, String lastLoginDate, String hiveSnsType, String userId, String deviceName, String osVersionFixed, String serverUid, long level, long isEmulator)
{
java.util.Map<String, Object> logData = new java.util.HashMap<String, Object>();
logData.put("changeUid", changeUid);
logData.put("thirdPartyAssent", thirdPartyAssent);
logData.put("tag1", tag1);
logData.put("hiveNewUser", hiveNewUser);
logData.put("dateTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); // The log's current time (in Korean time)
logData.put("timezone", timezone);
logData.put("channel", "C2S");
logData.put("source", source);
logData.put("serverId", serverId);
logData.put("osVer", osVer);
logData.put("vid", vid);
logData.put("uid", uid);
logData.put("appId", "com.gcp2.hivesdk.android.google.global.normal");
logData.put("wasRegistTimestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); // Server time
logData.put("company", company);
logData.put("model", model);
logData.put("lang", lang);
logData.put("class", class);
logData.put("os", os);
logData.put("appVer", appVer);
logData.put("cpu", cpu);
logData.put("market", market);
logData.put("clientIp", clientIp);
logData.put("guid", java.util.UUID.randomUUID().toString());
logData.put("sdkVer", sdkVer);
logData.put("serverIp", serverIp);
logData.put("category", "hive_test_login_log");
logData.put("did", did);
logData.put("grouping", grouping);
logData.put("newUser", newUser);
logData.put("guestUser", guestUser);
logData.put("lastLoginDate", lastLoginDate);
logData.put("hiveSnsType", hiveSnsType);
logData.put("userId", userId);
logData.put("deviceName", deviceName);
logData.put("osVersionFixed", osVersionFixed);
logData.put("serverUid", serverUid);
logData.put("level", level);
logData.put("isEmulator", isEmulator);
LOG.log("hive_login_log", logData);
}
# coding=utf-8
# pip install fluent-logger
from fluent import sender
import datetime
import uuid
def send_hive_login_log():
data = {
"ageGate13" : "Y",
"changeUid" : "90010023021",
"thirdPartyAssent" : "C",
"tag1" : "sample valuyes",
"hiveNewUser" : "Y",
"dateTime" : datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S"),
"timezone" : "GMT+09:00",
"channel" : "C2S",
"source" : "Web",
"serverId" : "1",
"osVer" : "4.3.1",
"vid" : "22222222",
"uid" : "11111111",
"appId" : "com.gcp2.hivesdk.android.google.global.normal",
"wasRegistTimestamp" : datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S"),
"company" : "C2S",
"model" : "SHW-M250S",
"lang" : "ko",
"class" : "sample value of class",
"os" : "A",
"appVer" : "1.0",
"cpu" : "armeabi-v7a",
"market" : "GO",
"clientIp" : "127.0.0.1",
"guid" : str(uuid.uuid4()),
"sdkVer" : "2.0.1",
"serverIp" : "127.0.0.2",
"category" : "hive_test_login_log",
"did" : "33333333",
"grouping" : "com.com2us.xxx",
"newUser" : "N",
"guestUser" : "N",
"lastLoginDate" : "2017-02-28 14:33:00",
"hiveSnsType" : "FB",
"userId" : "123456789",
"deviceName" : "SM-G935",
"osVersionFixed" : "9.2.1",
"serverUid" : "QA-2",
"level" : "7",
"isEmulator" : "1"
}
logger = sender.FluentSender("ha2union.gameserver.python", host='localhost', port=24224, timeout=10.0)
ret = logger.emit("hive_login_log", data)
return ret
<?php
// Required installing fluented to server in advance
require_once __DIR__.'/vendor/autoload.php';
use Fluent\Logger\FluentLogger;
function sink_log_hive_login_log() {
$data = array(
"ageGate13" => "Y",
"changeUid" => "90010023021",
"thirdPartyAssent" => "C",
"tag1" => "sample valuyes",
"hiveNewUser" => "Y",
"dateTime" => gmdate("Y-m-d H:i:s", time()),
"timezone" => "GMT",
"channel" => "C2S",
"source" => "Web",
"serverId" => "1",
"osVer" => "4.3.1",
"vid" => "22222222",
"uid" => "11111111",
"appId" => "com.gcp2.hivesdk.android.google.global.normal",
"wasRegistTimestamp" => gmdate("Y-m-d H:i:s", time()),
"company" => "C2S",
"model" => "SHW-M250S",
"lang" => "ko",
"class" => "sample value of class",
"os" => "A",
"appVer" => "1.0",
"cpu" => "armeabi-v7a",
"market" => "GO",
"clientIp" => "127.0.0.1",
"guid" => md5(uniqid(rand(), true)),
"sdkVer" => "2.0.1",
"serverIp" => "127.0.0.2",
"category" => "hive_test_login_log",
"did" => "33333333",
"grouping" => "com.com2us.xxx",
"newUser" => "N",
"guestUser" => "N",
"lastLoginDate" => "2017-02-28 14:33:00",
"hiveSnsType" => "FB",
"userId" => "123456789",
"deviceName" => "SM-G935",
"osVersionFixed" => "9.2.1",
"serverUid" => "QA-2",
"level" => "7",
"isEmulator" => "1"
);
$logger = new FluentLogger("unix:///dev/shm/fluentd.sock");
$result = $logger->post("ha2union.hive.hive_login_log", $data);
if ($result === false){
// Executes in deactivating the td-agent in local
// Saved in a temporary folder for each server
}
return $result;
}