コンテンツにスキップ

アプリケーションライブラリ

  • 下の画像のように、アプリケーションライブラリを使用することで、ログをログ収集サーバーに転送できます。

Note

他の言語のサンプルについては、Hive コンソール > 分析 > ログ定義に移動してください。詳細

// 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()));  // ログの現在時刻(韓国時間)
        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()));  // サーバー時間
        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" : "サンプル値",
        "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" : "クラスのサンプル値", 
        "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
// 必要な場合は、事前にサーバーにfluentedをインストールしてください


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" => "サンプル値", 
        "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" => "クラスのサンプル値", 
        "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){
            // ローカルでtd-agentを無効にする際に実行されます
                    // 各サーバーのために一時フォルダーに保存されます
    }

    return $result; 

}