repositories {
mavenCentral()
}
dependencies {
implementation 'com.nhncloud.android:nhncloud-logger:1.9.5'
...
}
If you use NhnCloudLogger without initialization, an initialization error occurs.
// Initialize Logger
NhnCloudLoggerConfiguration configuration = NhnCloudLoggerConfiguration.newBuilder()
.setAppKey(YOUR_APP_KEY) // Log & Crash Search AppKey
.build();
NhnCloudLogger.initialize(configuration);
NHN Cloud Logger provides log-sending functions of five levels.
// DEBUG level logs
static void debug(String message);
// INFO level logs
static void info(String message);
// WARN level logs
static void warn(String message);
// ERROR level logs
static void error(String message);
// FATAL level logs
static void fatal(String message);
NhnCloudLogger.warn("NHN Cloud Log & Crash Search!");
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.
static void setUserField(String field, Object value);
NhnCloudLogger.setUserField("nickname", "randy");
With listener registered, further tasks can be executed after logs are sent.
static void setLoggerListener(NhnCloudLoggerListener listener);
NhnCloudLogger.setLoggerListener(new NhnCloudLoggerListener() {
@Override
public void onSuccess(LogEntry log) {
// Sending logs succeeded.
}
@Override
public void onFilter(LogEntry log, LogFilter filter) {
// Filter by filter setting
}
@Override
public void onSave(LogEntry log) {
// Save within SDK for re-sending if log-sending fails due to network errors
}
@Override
public void onError(LogEntry log, Exception e) {
// Sending logs failed.
}
});
When an unexpected crash occurs in an app, NHN Cloud Logger records such crash information in the server.
Sending crash logs can be enabled or disabled by using setEnabledCrashReporter() .
// Initialize Logger
NhnCloudLoggerConfiguration configuration = NhnCloudLoggerConfiguration.newBuilder()
.setAppKey(YOUR_APP_KEY) // Log & Crash Search AppKey
.setEnabledCrashReporter(true) // Enable or Disable Crash Reporter
.build();
NhnCloudLogger.initialize(configuration);
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.
For Android platforms, exceptions from a try/catch sentence can be sent by using Handled Exception 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 & Cash Console, see Console User Guide.
// Send Exception Information
static void report(@NonNull String message, @NonNull Throwable throwable);
// Send Exception Information along with User Fields
static void report(@NonNull String message,
@NonNull Throwable throwable,
@Nullable Map<String, Object> userFields);
try {
// User Codes...
} catch (Exception e) {
Map<String, Object> userFields = new HashMap<>();
NhnCloudLogger.report("message", e, userFields);
}
Additional information can be set immediately after crash occurs. setUserField can be set anytime regardless of crash occurrence, whilesetCrashDataAdapter can be set at an accurate timing when a crash occurs.
static void setCrashDataAdapter(CrashDataAdapter adapter);
NhnCloudLogger.setCrashDataAdapter(new CrashDataAdapter() {
@Override
public Map<String, Object> getUserFields() {
Map<String, Object> userFields = new HashMap<>();
userFields.put("UserField", "UserValue");
return userFields;
}
});
Network Insights measure delay time and response values by calling URL registered in console. They may be applied to measure delays and response vales 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.
Network Insights can be enabled as follows.
URL can be set as follows.