This document describes how to use Log & Crash Search API.
Initializes NHN Cloud Logger SDK using the AppKey issued via Log & Crash Search.
API
Supported Platforms ■ UNITY_IOS ■ UNITY_ANDROID ■ UNITY_STANDALONE ■ UNITY_WEBGL
static void Initialize(GamebaseRequest.Logger.Configuration configuration)
Example
public static void InitializeSample()
{
var configuration = new GamebaseRequest.Logger.Configuration("USER_LOGGER_APP_KEY");
// configuration.enableCrashReporter = true; // Whether to send crash logs.
// configuration.enableCrashErrorLog = true; // Errro log is excluded by default. Use it if you want to collect error logs.
Gamebase.Logger.Initialize(configuration);
}
Sends logs to Log & Crash Server. NHN Cloud Logger SDK can send five different levels of logs listed below: * DEBUG * INFO * WARN * ERROR * FATAL
The log levels are as follows: * DEBUG > INFO > WARN > ERROR > FATAL
API
Supported Platforms ■ UNITY_IOS ■ UNITY_ANDROID ■ UNITY_STANDALONE ■ UNITY_WEBGL
static void Debug(string message, Dictionary<string, string> userFields = null)
static void Info(string message, Dictionary<string, string> userFields = null)
static void Warn(string message, Dictionary<string, string> userFields = null)
static void Error(string message, Dictionary<string, string> userFields = null)
static void Fatal(string message, Dictionary<string, string> userFields = null)
Example
public void DebugSample()
{
Dictionary<string, string> userFields = new Dictionary<string, string>()
{
{ "KEY_1", "VALUE_1" },
{ "KEY_2", "VALUE_2" },
};
Gamebase.Logger.Debug(
"MESSAGE",
userFields);
}
public void InfoSample()
{
Dictionary<string, string> userFields = new Dictionary<string, string>()
{
{ "KEY_1", "VALUE_1" },
{ "KEY_2", "VALUE_2" },
};
Gamebase.Logger.Info(
"MESSAGE",
userFields);
}
public void WarnSample()
{
Dictionary<string, string> userFields = new Dictionary<string, string>()
{
{ "KEY_1", "VALUE_1" },
{ "KEY_2", "VALUE_2" },
};
Gamebase.Logger.Warn(
"MESSAGE",
userFields);
}
public void ErrorSample()
{
Dictionary<string, string> userFields = new Dictionary<string, string>()
{
{ "KEY_1", "VALUE_1" },
{ "KEY_2", "VALUE_2" },
};
Gamebase.Logger.Error(
"MESSAGE",
userFields);
}
public void FatalSample()
{
Dictionary<string, string> userFields = new Dictionary<string, string>()
{
{ "KEY_1", "VALUE_1" },
{ "KEY_2", "VALUE_2" },
};
Gamebase.Logger.Fatal(
"MESSAGE",
userFields);
}
Sets user-defined fields you want. If a custom field is set, the setting value are sent along with a log to the server whenever Send Log API is called.
API
Supported Platforms ■ UNITY_IOS ■ UNITY_ANDROID ■ UNITY_STANDALONE ■ UNITY_WEBGL
static void SetUserField(string key, string value)
Example
public void SetUserFieldSample()
{
Gamebase.Logger.SetUserField("KEY", "VALUE");
}
Additional tasks are available after logs are sent if a listener is registered.
API
Supported Platforms ■ UNITY_IOS ■ UNITY_ANDROID ■ UNITY_STANDALONE ■ UNITY_WEBGL
static void SetLoggerListener(GamebaseCallback.Logger.ILoggerListener listener)
Example
public class LoggerListener : GamebaseCallback.Logger.ILoggerListener
{
public void OnError(GamebaseResponse.Logger.LogEntry log, string errorMessage)
{
// Sending logs failed
}
public void OnFilter(GamebaseResponse.Logger.LogEntry log, GamebaseResponse.Logger.LogFilter filter)
{
// The logs were filtered out and not sent.(Refer to AddClashFilter API Guide)
}
public void OnSave(GamebaseResponse.Logger.LogEntry log)
{
// If log transmission fails due to network disconnection, the log is saved in a file for log retransmission.(The saved file cannot be checked.)
}
public void OnSuccess(GamebaseResponse.Logger.LogEntry log)
{
// Sending logs succeeded
}
}
public void SetLoggerListenerSample()
{
LoggerListener listener = new LoggerListener();
Gamebase.Logger.SetLoggerListener(listener);
}
When using Unity, sometimes unwanted exception or crash logs are collected. NHN Cloud Logger SDK supports a feature that filters out crash logs that you do not want to collect. If crashFilter returns true, the log is filtered out.
[Caution]
This feature is only to deal with Unity exceptions
API
Supported Platforms ■ UNITY_IOS ■ UNITY_ANDROID ■ UNITY_STANDALONE ■ UNITY_WEBGL
static void AddCrashFilter(GamebaseCallback.Logger.CrashFilter filter)
static void RemoveCrashFilter(GamebaseCallback.Logger.CrashFilter filter)
Example
public GamebaseCallback.Logger.CrashFilter crashFilter = (crashLogData) =>
{
// If the return value is true, no log is sent.
// The properties of CrashLogData are the same as the parameters of Application.LogCallback on Unity.
// https://docs.unity3d.com/ScriptReference/Application.LogCallback.html
return crashLogData.Condition.Contains("UnityEngine.Debug.Log");
};
public void AddCrashFilterSample()
{
Gamebase.Logger.AddCrashFilter(crashFilter);
}
public void RemoveCrashFilterSample()
{
Gamebase.Logger.RemoveCrashFilter(crashFilter);
}
In addition to general/crash logs, you can send exception-related content in the try/catch syntax using Report API. The exception logs you sent can be viewed in the console by clicking Log & Crash Search > App Crash Search and clicking Handled under Error Type.
API
Supported Platforms ■ UNITY_IOS ■ UNITY_ANDROID ■ UNITY_STANDALONE ■ UNITY_WEBGL
static void Report(GamebaseLoggerConst.LogLevel logLevel, string message, string logString, string stackTrace)
Example
public void ReportSample(Exception e)
{
Gamebase.Logger.Report(GamebaseLoggerConst.LogLevel.ERROR, "message", e.Message, e.StackTrace);
}