- Print
- PDF
Android SDK v2
- Print
- PDF
Available in Classic and VPC
In Using Android SDK v2, it describes how to use Android SDK v2, which is provided by Effective Log Search & Analytics 2.0 service.
The following describes how to use SDK.
1. Preparation
2. Install SDK
3. Initialize SDK
4. Add permission for SDK
5. Use SDK
1. Preparation
The following describes the preparations for installing Android SDK.
- In NAVER Cloud Platform's console, Create project.
- Check the txtToken value in Project detail page.
- Download Android SDK v2.
2. Install Android SDK v2
The following describes how to install Android SDK v2.
- Unzip the downloaded SDK file.
- Save the SDK file in the
libs
folder of the Android project where SDK is to be installed.- When using the Thrift protocol: save
nelo2-android-sdk-common-SDK버전명.jar
andnelo2-android-sdk-thrift-SDK버전명.jar
files - When using the HTTPS protocol: save
nelo2-android-sdk-common-SDK버전명.jar
andnelo2-android-sdk-https-SDK버전명.jar
files - Starting from NELO SDK 0.9.0, the library files to be added to the libs folder are different depending on the protocol.
- <example>
..... android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } ..... repositories{ flatDir{ dirs 'libs' } } ..... dependencies { implementation (name: 'nelo2-android-sdk-common', version: '0.12.0', ext: 'aar') implementation (name: 'nelo2-android-sdk-https', version: '0.12.0', ext: 'aar') implementation (name: 'nelo2-android-sdk-thrift', version: '0.12.0', ext: 'aar') implementation (name: 'tink-android', version: '1.4.0', ext: 'jar') } .....
- When using the Thrift protocol: save
3. Initialize Android SDK v2
You can initialize Effective Log Search & Analytics 2.0 Android SDK in the following two ways.
- Call init method at the Main Activity
- Transfer logs without creating a crash dialog when an app crash occurs
- <example>
public class MainActivity extends Activity { ..... @Override protected void onCreate(Bundle savedInstanceState) { ..... NeloLog.init(getApplication(), "elsa-col.ncloud.com", 10006, "__Project_ID__", "__ProjectVersion__"); ..... } }
- Call init method at Application
- @NeloConf Use along with the annotation
- Export a crash dialog transferring the crash log following the settings when an app crash occurs
- <example>
@NeloConf( collectorUrl = "elsa-col.ncloud.com", // Effective Log Search & Analytics 2.0 Collector URL (required) serverPort = Nelo2Constants.SERVER_PORT_THRIFT, // Effective Log Search & Analytics 2.0 Port Number (required) projectName = "72356c50401b8e20_testproject", // Effective Log Search & Analytics 2.0 Project ID (required) mode = CrashReportMode.DIALOG, // Effective Log Search & Analytics 2.0 CrashReportMode (optional, Default : SLIENT) sendMode = NeloSendMode.ALL, // Effective Log Search & Analytics 2.0 SendMode (optional, Default : ALL) debug = true, // Effective Log Search & Analytics 2.0 Debug mode (optional, Default : false) logSource = "elsa-android", // Effective Log Search & Analytics 2.0 Log Source (optional, Default : nelo2-android) logType = "development", // Effective Log Search & Analytics 2.0 Log Type (optional, Defalut : nelo2-log) resDialogText = R.string.crash_dialog_text, // Crash Report Doalog Text (required, if you set mode CrashReportMode.Dialog) resDialogTitle = R.string.crash_dialog_title // Crash Report Dolog Title (required, if you set mode CrashReportMode.Dialog) ) public class MainApplication extends Application { ..... @Override protected void onCreate() { ..... NeloLog.init(this); ..... } } .....
- For more information on initialization method, see Initialization API.
- Initialize by calling init method at Application is recommended.
4. Add permission for Android SDK v2
You need to add permission to import information, such as network status, device information, telecommunications company, and Logcat. Add the following content to the AndroidManifest.xml file.
.....
/** AndroidManifest.xml **/
<!-- Permission for the Internet access to transfer Nelo log (Required) -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Permission to access information of the mobile phone, such as platform and carrier (Required) -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- Permission to access Network access (Required) -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- Permission to save data as files when network access is not allowed -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
.....
<!-- Permission to read logcat logs (optional) -->
<uses-permission android:name="android.permission.READ_LOGS" />
.....
<!-- Need to set a name if the application is created to use the Crash Report Dialog-->
<application ..... android:name="ApplicationName">
.....
<!-- Receiver that should be added to send logs only when the network status is WiFi mode by checking the network status -->
<!-- No need to add it when using the SendMode as All -->
<receiver android:name="com.nhncorp.nelo2.android.util.NetworkStatusReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
.....
<!-- Activity to use the Crash Report Dialog -->
<!-- No need to add it when not using CrashReportMode.DIALOG -->
<activity android:name="com.nhncorp.nelo2.android.CrashReportDialog"
android:theme="@android:style/Theme.Dialog"
android:launchMode="singleInstance"
android:excludeFromRecents="true"
android:finishOnTaskLaunch="true" />
.....
5. Use SDK
Refer to the following actual codes that use Effective Log Search & Analytics 2.0 Android SDK and transfer logs to the projects.
.....
import com.navercorp.nelo2.android.NeloLog;
.....
public class MainActivity extends Activity {
.....
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NeloLog.init(getApplication(),"Effective Log Search & Analytics-COLLECTOR-URL",new ThriftFactory(),"ELSA-PROJECT-NAME","PROJECT-VERSION");
NeloLog.debug("ErrorCode","Message","ErrorLocation"); // Send Debug Message
NeloLog.info("ErrorCode","Message","ErrorLocation"); // Send Info Message
NeloLog.warn("ErrorCode","Message","ErrorLocation"); // Send Warn Message
NeloLog.error("ErrorCode","Message","ErrorLocation"); // Send Error Message
NeloLog.fatal("ErrorCode","Message","ErrorLocation"); // Send Fatal Message
String nullString = null;
try{
nullString.toString();
}catch(Exception e){
NeloLog.crash(e,"ErrorCode","Message","ErrorLcoation"); // Send caught crash Message
}
NeloLog.debug("ErrorCode","Message","ErrorLocation"); // Send message with custom message
int i = 10 / 0; // Nelo send uncaught exception
}
.....
Android SDK v2 API details
Android SDK v2 provides the following API.
- Initialization API
- System Field setting API
- Custom Field setting API
- Logcat setting API
- Logcat transferring API
- Log transferring API
- Log transferring API (including exceptions)
- Crash callback API
- Option setting API
Initialization API
Android SDK v2 provides initialization method for each calling method.
- You need to initialize NeloLog first before using NeloLog to make it work normally. Initialize only one time.
- You need to initialize at Application to use Crash Report Dialog.
Initialize at Main Activity
Here are the APIs that should be initialized at Main Activity.
static boolean init(Application application, String reportServer, ProtocolFactory protocolFactory, String appId, String projectVersion)
static boolean init(Application application, String reportServer, ProtocolFactory protocolFactory, String appId, String projectVersion, String userId)
The following describes each parameter.
Parameter | Description |
---|---|
Application application | Android's application information
|
String reportServer | Log collecting server's address
|
ProtocolFacotry protocolFactory | Connecting protocol of the log collecting server
|
String appId | Project key (refer to Project details) |
String appVersion | Version information of the app to transfer logs |
String userId | User ID to transfer (optional) |
<example>
NeloLog.init(getApplication(), "elsa-col.ncloud.com", new ThriftFactory(), "72356c50401b8e20_testproject", "1.0.0");
Initialization at Application
Here are the APIs that should be initialized at Application. You must enter the @NeloConf
annotation together.
boolean init (Application application)
The following describes each parameter.
Parameter | Description |
---|---|
Application application | Android's application information. In general, enter getApplication() |
<example>
@NeloConf(
collectorUrl = "elsa-col.ncloud.com", // Effective Log Search & Analytics Collector URL (required)
protocolFactoryClass = ThriftFactory.class, // Effective Log Search & Analytics Protocol Type, you can choose to use ThriftFactory.class or HTTPSFactory.class (required)
projectName = "72356c50401b8e20_testproject", // Effective Log Search & Analytics projectId (required)
mode = CrashReportMode.DIALOG, // Effective Log Search & Analytics CrashReportMode (optional, Default : SLIENT)
sendMode = NeloSendMode.ALL, // Effective Log Search & Analytics SendMode (optional, Default : ALL)
debug = true, // Effective Log Search & Analytics Debug mode (optional, Default : false)
logSource = "Effective Log Search & Analytics-android", // Effective Log Search & Analytics Log Source (optional, Default : nelo2-android)
logType = "development", // Effective Log Search & Analytics Log Type (optional, Defalut : nelo2-log)
resDialogText = R.string.crash_dialog_text, // Crash Report Doalog Text (required, if you set mode CrashReportMode.Dialog)
resDialogTitle = R.string.crash_dialog_title // Crash Report Dolog Title (required, if you set mode CrashReportMode.Dialog)
enableSendLogCatEvents = true, // Enable LogCat (optional, Default : false)
enableSendLogCatMain = true, // Enable LogCat (optional, Default : false)
enableSendLogCatRadio = true // Enable LogCat (optional, Default : false)
)
public class MainApplication extends Application {
.....
@Override
protected void onCreate() {
.....
NeloLog.init(this);
.....
}
}
.....
System Field setting API
Here are the APIs that set the System Field value. The value you set will be forwarded equally from all logs that will be transferred in the future.
Set user ID
Here are the APIs that set user ID.
static void void setUserID(String userID)
static void setUserID(String instanceName, String userID)
The following describes each parameter.
Parameter | Description |
---|---|
String userID | User ID |
String instanceName | Dynamic instance name |
<example>
NeloLog.setUserID("test");
Set logSource information
Here are the APIs that set logSource.
static void setLogSource(String logSource)
static void setLogSource(String instanceName, String logSource)
The following describes each parameter.
Parameter | Description |
---|---|
String logSource | logSource information |
String instanceName | Dynamic instance name |
<example>
NeloLog.setLogSource("NELO2 Android SDK LogSource");
Set log type
Here are the APIs that set logType.
static void setLogType(String logType)
static void setLogType(String instanceName, String logType)
The following describes each parameter.
Parameter | Description |
---|---|
String logType | logType information |
String instanceName | Dynamic instance name |
<example>
NeloLog.setLogType("NELO2 Android SDK LogType");
Custom Field setting API
Here are the APIs that set the Custom Field value.
Set Custom Field's key and value
Here are the APIs that set the Custom Field's key and value. The set value will be transferred as the same customized message in all logs to be sent in the future.
static void putCustomMessage(String key, String value)
static void putCustomMessage(String instanceName, String key, String value)
The following describes each parameter.
Parameter | Description |
---|---|
String key | Key of the value to save (field name) |
String value | Value of the value to be saved (user message) |
String instanceName | Dynamic instance name |
<example>
NeloLog.putCustomMessage("test","test value");
Delete customized message
Here are the APIs that delete the customized message that has the same key by deleting the Custom Field's key.
static void removeCustomMessage(String key)
static void removeCustomMessage(String instanceName, String key)
The following describes each parameter.
Parameter | Description |
---|---|
String key | Key of the value to delete (field name) |
String instanceName | Dynamic instance name |
<example>
NeloLog.removeCustomMessage("test");
Delete all customized messages
Here are the APIs that delete all customized messages.
static void clearCustomMessage()
static void clearCustomMessage(String instanceName)
The following describes each parameter.
Parameter | Description |
---|---|
String instanceName | Dynamic instance name |
<example>
NeloLog.clearCustomMessage();
Logcat setting API
Here are the APIs that set Logcat.
- This API sets whether to transfer
LogCat buffer
when a crush occurs in the app. - The
LogCat buffer
types of Logcat are basicallyMain
,Radio
, andEvents
.
static void setEnableLogcatMain(boolean enabled)
static void setEnableLogcatRadio(boolean enabled)
static void setEnableLogcatEvents(boolean enabled)
static void setEnableLogcatMain(String instanceName,boolean enabled)
static void setEnableLogcatRadio(String instanceName,boolean enabled)
static void setEnableLogcatEvents(String instanceName,boolean enabled)
The following describes each parameter.
Parameter | Description |
---|---|
boolean enabled | Set whether to transfer Logcat buffer |
String instanceName | Dynamic instance name |
<example>
NeloLog.setEnableLogcatMain(true);
Logcat transferring API
Here are the APIs that transfer Logcat.
- This function transfers
logcat buffer
to NELO at a certain time. - This function is not relevant to
setEnableLogcat
function. - This function is a heavy task. Try not to call repeatedly if possible (recommended).
static void sendLogcat(String errorCode, String message)
static void sendLogcat(String errorCode, String message, String errorLocation)
static void sendLogcatWithInstanceName(String instanceName, String errorCode, String message)
static void sendLogcatWithInstanceName(String instanceName, String errorCode, String message, String errorLocation)
The following describes each parameter.
Parameter | Description |
---|---|
String errorCode | The value that is mapped to NELO's errorCode field |
String message | The value that is mapped to NELO's body |
String location | Location where the log occurred |
String instanceName | Dynamic instance name |
<example>
NeloLog.sendLogcat("ErrorCode","Message");
Log transferring API
Here are the APIs that transfer logs.
Uses functions by logLevel.
- logLevel: Fatal, Error, Warn, Info, and Debug
static void debug(String errorCode,String message,String location)
static void debug(String errorCode,String message)
static void info(String errorCode,String message,String location)
static void info(String errorCode,String message)
static void warn(String errorCode,String message,String location)
static void warn(String errorCode,String message)
static void error(String errorCode,String message,String location)
static void error(String errorCode,String message)
static void fatal(String errorCode,String message,String location)
static void fatal(String errorCode,String message)
The following describes each parameter.
Parameter | Description |
---|---|
String errorCode | The value that is mapped to NELO's errorCode field |
String message | The value that is mapped to NELO's body |
String location | Location where the log occurred |
<example>
NeloLog.error("test","Test value","location");
NeloLog.debug("test 2","Test value ")
Log transferring API (including exceptions)
Here are the APIs that transfer logs including exception information.
Transfer error logs
Here are the APIs that transfer error logs including exception information.
Uses functions by logLevel.
- logLevel: Fatal, Error, Warn, Info, and Debug
static void debug(Throwable t, String errorCode,String message,String location)
static void debug(Throwable t, String errorCode,String message)
static void info(Throwable t, String errorCode,String message,String location)
static void info(Throwable t, String errorCode,String message)
static void warn(Throwable t, String errorCode,String message,String location)
static void warn(Throwable t, String errorCode,String message)
static void error(Throwable t, String errorCode,String message,String location)
static void error(Throwable t, String errorCode,String message)
static void fatal(Throwable t, String errorCode,String message,String location)
static void fatal(Throwable t, String errorCode,String message)
// For transferring dynamic instance logs
static void debugWithInstanceName(String instanceName, Throwable t, String errorCode, String message)
static void debugWithInstanceName(String instanceName, Throwable t, String errorCode, String message, String errorLocation)
static void infoWithInstanceName(String instanceName, Throwable t, String errorCode, String message)
static void infoWithInstanceName(String instanceName, Throwable t, String errorCode, String message, String errorLocation)
static void warnWithInstanceName(String instanceName, Throwable t, String errorCode, String message)
static void warnWithInstanceName(String instanceName, Throwable t, String errorCode, String message, String errorLocation)
static void errorWithInstanceName(String instanceName, Throwable t, String errorCode, String message)
static void errorWithInstanceName(String instanceName, Throwable t, String errorCode, String message, String errorLocation)
static void fatalWithInstanceName(String instanceName, Throwable t, String errorCode, String message)
static void fatalWithInstanceName(String instanceName, Throwable t, String errorCode, String message, String errorLocation)
The following describes each parameter.
Parameter | Description |
---|---|
Throwable t | Exception information
|
String errorCode | The value that is mapped to NELO's errorCode field |
String message | The value that is mapped to NELO's body |
String location | Location where the log occurred
|
String instanceName | Dynamic instance name |
<example>
try{
int a = 10 / 0;
} catch (Exception e) {
NeloLog.error(e,"Error_Code",e.getMessage());
}
Transfer crash logs
Here are the APIs that transfer crash logs including exception information in exceptional instances.
- As soon as the user calls the crash function, the crash log and
DmpData
field are transferred to NELO. - Call only when it is necessary for the app's performance (recommended).
static void crash(Throwable t, String errorCode,String message,String location)
static void crash(Throwable t, String errorCode,String message)
<example>
try{
int a = 10 / 0;
} catch (Exception e) {
NeloLog.crash(e,"Error_Code",e.getMessage());
}
Crash callback API
You can call the user-defined functions before sending the crash log when a crash occurs. Here are the crash callback APIs.
static void setNeloCrashCallback(NeloCrashCallback neloCrashCallback)
The following describes each parameter.
Parameter | Description |
---|---|
NeloCrashCallback neloCrashCallback | Function called when a crash occurs
|
<example>
NeloLog.setNeloCrashCallback(new NeloCrashCallback() {
@Override
public boolean beforeSendNeloCrash() {
Log.e("[AndroidApp]", "______________[[ beforeSendNeloCrash ]]__________________");
return true;
}
@Override
public boolean beforeInstanceSendNeloCrash(String instanceName) {
Log.e("[AndroidApp]", "______________[[ beforeInstanceSendNeloCrash ] " + instanceName + "]__________________");
return Nelo2Constants.NELO_DEFAULT_INSTANCE_NAME.equalsIgnoreCase(instanceName);
}
@Override
public void finishInstanceSendNeloCrash(String instanceName) {
Log.e("[AndroidApp]", "______________[[ finishInstanceSendNeloCrash ] " + instanceName + "]__________________");
}
@Override
public void finishSendNeloCrash() {
Log.e("[AndroidApp]", "______________[[ finishSendNeloCrash ]]__________________");
}
});
Option setting API
Here are the Option setting APIs.
Set whether to use NELO
Here are the APIs that set whether to use NELO.
static boolean getNeloEnable()
static void setNeloEnable(boolean enabled)
The following describes each parameter.
Parameter | Description |
---|---|
boolean enabled | Set whether to use NELO
|
Set whether to use the Debug mode
When the Debug mode is used, detailed logs for Logcat are recorded. Here are the APIs that set whether to use Debug mode.
static boolean getDebug()
static void setDebug(boolean enabled)
The following describes each parameter.
Parameter | Description |
---|---|
boolean enabled | Whether to use Debug mode
|
Set crash transfer method
Here are the APIs that set crash transfer method.
static CrashReportMode getCrashMode()
static void setCrashMode(CrashReportMode mode)
The following describes each parameter.
Parameter | Description |
---|---|
CrashReportMode mode | Set crash transfer method when an app crash occurs
|
Set log transfer method
Here are the APIs that set log transfer method.
static NeloSendMode getNeloSendMOde()
static void setNeloSendMOde(NeloSendMode mode)
The following describes each parameter.
Parameter | Description |
---|---|
NeloSendMode mode | Set log transfer method |
The following shows the log transfer method by network, depending on the parameter setting value.
ALL
Network status Transfer method 3g Transfer Wi-Fi Transfer Not Connected Not transferred, saving file ONLY_WIFI_WITH_FILE_SAVE
Network status Transfer method 3g Not transferred, saving file Wi-Fi Transfer Not Connected Not transferred, saving file ONLY_WIFI_WITHOUT_FILE_SAVE
Network status Transfer method 3g Not transferred, not saving file Wi-Fi Transfer Not Connected Not transferred, not saving file
When setting ONLY_WIFI_WITH_FILE_SAVE
or ONLY_WIFI_WITHOUT_FILE_SAVE
, you need to add permission to check the network status. (Refer to Add permission for Android SDK v2)
Set the maximum file size of the log save file
Here are the APIs that set the maximum file size of the log save file.
- Default of the maximum file size of the log save file is 1 MB (1024 x 1024 bytes).
- When the log file's size is larger than the maximum value, it is saved after deleting old data.
- For how to set logs to be saved as files, see Set log transfer method.
static int getMaxFileSize()
static void setMaxFileSize(int max_file_size)
static int getMaxFileSize(String instanceName)
static void setMaxFileSize(String instanceName, int max_file_size)
The following describes each parameter.
Parameter | Description |
---|---|
int max_file_size | The maximum file size of the log save file |
String instanceName | Dynamic instance name |
Transfer logs saved in the queue and files to the server
Here are the APIs that transfer logs temporarily saved in the queue and files to the server.
static void flush()
View the current size of the log save file
Here are the APIs that view (return) the total size of the files used by the current NELO logs.
static long getAllNeloSaveLogFileSize()
Set whether to transfer previous files to the server
Here are the APIs that set whether to read previous files and transfer them to the server.
- Use the file name created with a hash value by combining
InstanceName
and the project name. - Call this function when you have to delete existing files because the project name and instance name have changed.
- When the
flushFile
value istrue
(default value), read all the content before deleting the previous files and save them in the queue.
static boolean clearSavedNeloLogFile(boolean flushFile)
The following describes each parameter.
Parameter | Description |
---|---|
boolean flushFile | Determines whether to read previous files and transfer them to the server |
Set loglevel
Here are the APIs that transfer logs over the loglevel.
- The default is
Nelo2LogLevel.DEBUG
. - When the user makes requests to transfer logs to the server explicitly, such as
crash
orflush
, ignoreLogLevel
's filter value.
static void setLogLevelFilter(Nelo2LogLevel loglevel)
static Nelo2LogLevel getLogLevelFilter()
The following describes each parameter.
Parameter | Description |
---|---|
Nelo2LogLevel loglevel | Transfers logs over loglevel to NELO |