apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.nhncloud.android:nhncloud-unity-logger:1.4.1'
**DEPS**}
Menu | List | Setting | Recommended Setting |
---|---|---|---|
Edit > Project Settings > Player | Debugging and crash reporting | On .Net UnhandledException | Silent Exit |
Edit > Project Settings > Player | Debugging and crash reporting | Enable CrashReport API | Disabled |
Edit > Project Settings > Player | Other Settings | Script Call Optimization | Slow and Safe |
using Toast.Logger;
Set Appkey issued from Log & Crash Search as ProjectKey.
var loggerConfiguration = new ToastLoggerConfiguration
{
ProjectKey = "YOUR_PROJECT_KEY"
};
ToastLogger.Initialize(loggerConfiguration);
NHN Cloud Logger can send logs of five levels. User fields may be additionally sent.
// DEBUG level logs
ToastLogger.Debug(message);
ToastLogger.Debug(message, userFields);
// INFO level logs
ToastLogger.Info(message);
ToastLogger.Info(message, userFields);
// WARN level logs
ToastLogger.Warn(message);
ToastLogger.Warn(message, userFields);
// ERROR level logs
ToastLogger.Error(message);
ToastLogger.Error(message, userFields);
// FATAL level logs
ToastLogger.Fatal(message);
ToastLogger.Fatal(message, userFields);
ToastLogger.Debug("NHN Cloud Log & Crash Search!", new Dictionary<string, string>
{
{ "Scene", "Main" }
});
Set a user-defined field as wanted. With user-defined field setting, set values are sent to server along with logs, every time Log Sending API is called.
ToastLogger.SetUserField(userField, userValue);
ToastLogger.SetUserField("GameObject", gameObject.name);
public interface IToastLoggerListener
{
void OnSuccess(LogEntry log);
void OnFilter(LogEntry log, LogFilter filter);
void OnSave(LogEntry log);
void OnError(LogEntry log, string errorMessage);
}
static void SetLoggerListener(IToastLoggerListener listener);
public class SampleLoggerListener : IToastLoggerListener
{
public void OnSuccess(LogEntry log)
{
// Sending logs succeeded
}
public void OnFilter(LogEntry log, LogFilter filter)
{
// Filter by filter setting
}
public void OnSave(LogEntry log)
{
// Save within SDK for re-sending if log-sending fails due to network errors
}
public void OnError(LogEntry log, string errorMessage)
{
// Sending logs failed
}
}
ToastLogger.SetLoggerListener(new SampleLoggerListener());
NHN Cloud Logger classifies Unity's crashes into two categories.
Why is the log outputted as LogException also collected as a crash log? This is because some third-party libraries expose exceptions in user code through LogException. If you want to filter out the crash log, refer to Filtering the Crash Log below.
With ToastLogger initialized, a crash log is automatically sent when it occurs crash under the mobile environment or when it occurs the unexpected exception in Unity. To disable crash log delivery, set false for EnableCrashReporter property of the ToastLoggerConfiguration object. For more information on crash logs of each platform, check the links below:
var loggerConfiguration = new ToastLoggerConfiguration
{
ProjectKey = "YOUR_PROJECT_KEY",
EnableCrashReporter = false // Disable crash logs
};
If the User ID is set, you can check the user-specific crash experience in the 'Crash User' section of the Log & Crash Search console. User ID setting can be checked in Getting Started.
Crash listener only works when it occurs unexpected exception in Unity Crash listener is not supported for crashes on the native platform.
public delegate void CrashListener(bool isSuccess, LogEntry logEntry);
public static void SetCrashListener(CrashListener listener);
ToastLogger.SetCrashListener((isSuccess, log) =>
{
if (isSuccess)
{
Application.Quit();
}
});
public delegate bool CrashFilter(CrashLogData logData);
public class CrashLogData
{
public LogType LogType { get; }
public string Condition { get; }
public string StackTrace { get; }
}
public static void AddCrashFilter(CrashFilter filter);
ToastLogger.AddCrashFilter(crashLogData => crashLogData.Condition.Contains("UnityEngine.Debug.Log"));
Exceptions from a try/catch sentence, as well as general/crash logs, can be sent by using Report API of NHN Cloud Logger. Such exception logs can be queried by filtering for Handled, from error type of "Log & Crash Search Console" > "App Crash Search Tab". For more usage details on Log & Crash Console, see Console User Guide.
// Send Handled Exception Logs
var logLevel = ToastLogLevel.ERROR;
ToastLogger.Report(logLevel, message, exception);
try
{
doSomethingWrong();
}catch(Exception e)
{
// Debug, Info, Warn, Error, and Fatal are available.
ToastLogger.Report(ToastLogLevel.ERROR, "YOUR_MESSAGE", exception);
}
Network Insights measure delay time and response values by calling URL registered in console. They may be applied to measure delays and response values of many countries around the world (according to national codes on a device).
With Network Insights enabled in console, it is requested for one time via URL registered in the console when NHN Cloud Logger is initialized.