[Deprecated] Log & Crash Unity Android SDK 버전은 더 이상 지원되지 않습니다. TOAST SDK를 이용해 주시기 바랍니다.
Log & Crash Unity SDK는 Log & Crash Search 수집 서버에 로그를 보내는 기능을 제공합니다. Log & Crash Unity SDK 특·장점은 다음과 같습니다.
TOAST Document에서 Unity SDK를 받을 수 있습니다.
[DOCUMENTS] > [Download] > [Analytics > Log & Crash Search] > [Unity SDK]
샘플의 실행은 Assets > LogNCrash > Sample > SampleScene을 더블클릭하여 실행합니다. 샘플에는 초기화, 로그 전송, 에러 발생에 대한 예제가 기술되어 있습니다.
Unity 메뉴바에서 LogNCrash> Edit Settings를 선택하여 LogNCrashSettings를 생성합니다. LogNCrashSettings는 AssetDatabase로 사용자 앱키와 SDK 동작을 정의 합니다.
LogNCrashSettings에 정보를 입력하고 LogNCrash객체의 파라미터가 없는 Initialize 함수를 호출하면 LogNCrashSettings에서 정보를 읽어와 초기화를 시도 합니다.
using Toast.LogNCrash;
namespace Toast.LogNCrash
{
public class SampleScript : MonoBehaviour
{
void Start ()
{
LogNCrash.Initialize ();
}
}
}
using Toast.LogNCrash;
namespace Toast.LogNCrash
{
public class SampleScript : MonoBehaviour
{
void Start ()
{
LogNCrash.Initialize ("https://api-logncrash.cloud.toast.com", "appkey", "1.0.0", 80, true);
LogNCrash.StartSendThread ();
}
}
}
public static void AddCustomField(string key, string val)
public static void RemoveCustomField(string key)
public static void RemoveAllCustomFields()
public static void SetLogSource(string value)
public static string GetLogSource()
public static void SetLogType(string value)
public static string GetLogType()
- html > index.html을 참고해 주시기 바랍니다.
public static void SetEnableHost:(bool flag)
//send info log message
public static void Info(string strMsg)
//send debug log message
public static void Debug(string strMsg)
//send warn log message
public static void Warn(string strMsg)
//send fatal log message
public static void Fatal(string strMsg)
//send error log message
public static void Error(string strMsg)
//send Handled info log message
public static void Info(string strMsg, Exception e)
//send Handled debug log message
public static void Debug(string strMsg, Exception e)
//send Handled warn log message
public static void Warn(string strMsg, Exception e)
//send Handled fatal log message
public static void Fatal(string strMsg, Exception e)
//send Handled error log message
public static void Error(string strMsg, Exception e)
try{
// Exception code
}catch(Exception e){
LogNCrash.Info("handled exception message", e)
}
public void Crash_Send_Complete_Callback(string message) {
Debug.Log("Crash_Send_Complete_Callback : " + message);
}
void Start() {
LogNCrashCallBack.ExceptionDelegate += Crash_Send_Complete_Callback;
}
public static void SetUserId(string userID)
public static string GetUserID()
2.4.0 이상 SDK 부터 일반 로그에 중복 제거 로직이 적용되었습니다. 초기화 시 중복 제거 로직이 활성화됩니다.
일반 로그의 경우 body와 logLevel이 같은 로그가 발생한 경우 전송하지 않습니다.
크래시 로그의 경우 stackTrace와 condition 값이 같은 로그가 발생한 경우 전송하지 않습니다.
원하지 않는 경우 초기화 이후, 아래 함수를 통해 기능을 비활성화시킬 수 있습니다.
public static void SetDeduplicate(bool flag)
true :(Default 값) 중복 제거 로직 활성화
false: 중복 제거 로직 비활성화
1.File->Build Settings 클릭합니다.
2.Build settings에서 Build And Run 클릭합니다.
Unity의 Crash는 Unity Engine에서 발생하는 Crash와 Android Naitve에서 발생하는 Crash로 구분됩니다.
Proguard가 적용되지 않은 경우 별도의 Symbol 등록 과정이 필요하지 않습니다.
Proguard가 적용된 경우 Native 레벨의 Crash 해석를 위하기 위해서는 mapping.txt 파일을 웹 콘솔 > Analytic > Log & Crash Search > Settings > 심볼 파일 탭에 등록해야 합니다.
mapping.txt 파일은 proguard 폴더 하위에 생성됩니다.
LogNCrash.SetCrashHanlder (false);
LogNCrash.Initialize ();
void OnEnable()
{
Application.logMessageReceived += HandleLog;
}
void HandleLog(string logString, string stackTrace, LogType type)
{
if (LogNCrash.isInitialized) {
LogNCrash.unity3dHandleException (logString, stackTrace, type);
}
}
using UnityEditor;
using UnityEngine;
using Toast.LogNCrash.Implementation;
public class lncAndroidBuildPipeline: MonoBehaviour
{
[MenuItem("Build/Build Android (Alpha)")]
public static void AndroidAlphaBuildScript()
{
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
buildPlayerOptions.scenes = new[] {"Assets/Toast/Sample/Scene/Command/commandScene.unity"};
buildPlayerOptions.locationPathName = "AndroidBuild.apk";
buildPlayerOptions.target = BuildTarget.Android;
buildPlayerOptions.options = BuildOptions.AutoRunPlayer;
LogNCrashSettings.Setter_BuildType = LogNCrashSettings.BuildType.alpha;
BuildPipeline.BuildPlayer(buildPlayerOptions);
}
[MenuItem("Build/Build Android (Real)")]
public static void AndroidRealBuildScript()
{
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
buildPlayerOptions.scenes = new[] {"Assets/Toast/Sample/Scene/Command/commandScene.unity"};
buildPlayerOptions.locationPathName = "AndroidBuild.apk";
buildPlayerOptions.target = BuildTarget.Android;
buildPlayerOptions.options = BuildOptions.AutoRunPlayer;
LogNCrashSettings.Setter_BuildType = LogNCrashSettings.BuildType.real;
BuildPipeline.BuildPlayer(buildPlayerOptions);
}
}
using Toast.LogNCrash.Implementation;
void Start () {
if (LogNCrashSettings.Getter_BuildType == LogNCrashSettings.BuildType.real) {
SetReal ();
} else if (LogNCrashSettings.Getter_BuildType == LogNCrashSettings.BuildType.alpha) {
SetAlpha ();
} else {
UnityEngine.Debug.Log ("Default Type");
}
}
public enum BuildType{
real, alpha, beta, development, test
}