Android SDK v3 사용 방법
    • PDF

    Android SDK v3 사용 방법

    • PDF

    Article Summary

    Classic/VPC 환경에서 이용 가능합니다.

    개요

    이 장에서는 Effective Log Search & Analytics NELO Android SDK의 사용 방법을 설명합니다.

    NELO는 Effective Log Search & Analytics의 프로젝트 코드 네임입니다.

    Effective Log Search & Analytics의 Android SDK는 Android OS 4.4 이상(API 19 이상)을 지원합니다.

    다운로드

    API 목록

    // Initialization functions
    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)
    static boolean init(Application application)
    static boolean isInit()
    
    //System field setting functions
    static void setUserID(String userID)
    static void setLogType(String logType)
    static void setLogSource(String logSource)
    
    //Custom field setting functions
    static void putCustomMessage(String key,String value)
    static void removeCustomMessage(String key)
    static void clearCustomMessage()
    
    //Logcat setting and transfer functions
    static void setEnableLogcatMain(boolean enabled)
    static void setEnableLogcatRadio(boolean enabled)
    static void setEnableLogcatEvents(boolean enabled)
    static boolean clearLogcat()
    static void sendLogcat(String errorCode,String message)
    static void sendLogcat(String errorCode,String message,String errorLocation)
    
    // Log transfer functions
    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)
    
    // Log transfer functions (Including exceptions)
    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)
    static void crash(Throwable t, String errorCode,String message,String location)
    static void crash(Throwable t, String errorCode,String message)
    
    // Option setting functions
    static boolean getNeloEnable()
    static void setNeloEnable(boolean enabled)
    
    static boolean getDebug()
    static void setDebug(boolean enabled)
    
    static CrashReportMode getCrashMode()
    static void setCrashMode(CrashReportMode mode)
    
    static int getMaxFileSize()
    static void setMaxFileSize(int max_file_size)
    
    static boolean getSendInitLog()
    static void setSendInitLog(boolean enabled)
    
    static Nelo2LogLevel getLogLevelFilter()
    static void setLogLevelFilter(Nelo2LogLevel loglevel)
    
    static NeloSendMode getNeloSendMode()
    static void setNeloSendMode(NeloSendMode mode)
    
    // Dynamic Instance, you can use different instances to send logs to different projects registered in Effective Log Search & Analytics
    // Initialization functions
    static boolean initWithInstanceName(String instanceName, Application application, String reportServer, ProtocolFactory protocolFactory, String appId, String projectVersion)
    static boolean initWithInstanceName(String instanceName, Application application, String reportServer, ProtocolFactory protocolFactory, String appId, String projectVersion, String userId)
    static boolean isInit(String instance)
    
    //System field setting functions
    static void setUserID(String instanceName,String userID)
    static void setLogType(String instanceName,String logType)
    static void setLogSource(String instanceName,String logSource)
    
    //Custom field setting functions
    static void putCustomMessage(String instanceName,String key,String value)
    static void removeCustomMessage(String instanceName,String key)
    static void clearCustomMessage(String instanceName)
    
    //Logcat setting and transfer functions
    static void setEnableLogcatMain(String instanceName,boolean enabled)
    static void setEnableLogcatRadio(String instanceName,boolean enabled)
    static void setEnableLogcatEvents(String instanceName,boolean enabled)
    static boolean clearLogcat()
    static void sendLogcatWithInstanceName(String instanceName,String errorCode,String message)
    static void sendLogcatWithInstanceName(String instanceName,String errorCode,String message,String errorLocation)
    
    // Log transfer functions
    static void debugWithInstanceName(String instanceName,String errorCode,String message,String location)
    static void debugWithInstanceName(String instanceName,String errorCode,String message)
    static void infoWithInstanceName(String instanceName,String errorCode,String message,String location)
    static void infoWithInstanceName(String instanceName,String errorCode,String message)
    static void warnWithInstanceName(String instanceName,String errorCode,String message,String location)
    static void warnWithInstanceName(String instanceName,String errorCode,String message)
    static void errorWithInstanceName(String instanceName,String errorCode,String message,String location)
    static void errorWithInstanceName(String instanceName,String errorCode,String message)
    static void fatalWithInstanceName(String instanceName,String errorCode,String message,String location)
    static void fatalWithInstanceName(String instanceName,String errorCode,String message)
    
    // Log transfer functions (Including exceptions)
    static void debugWithInstanceName(String instanceName,Throwable t, String errorCode,String message,String location)
    static void debugWithInstanceName(String instanceName,Throwable t, String errorCode,String message)
    static void infoWithInstanceName(String instanceName,Throwable t, String errorCode,String message,String location)
    static void infoWithInstanceName(String instanceName,Throwable t, String errorCode,String message)
    static void warnWithInstanceName(String instanceName,Throwable t, String errorCode,String message,String location)
    static void warnWithInstanceName(String instanceName,Throwable t, String errorCode,String message)
    static void errorWithInstanceName(String instanceName,Throwable t, String errorCode,String message,String location)
    static void errorWithInstanceName(String instanceName,Throwable t, String errorCode,String message)
    static void fatalWithInstanceName(String instanceName,Throwable t, String errorCode,String message,String location)
    static void fatalWithInstanceName(String instanceName,Throwable t, String errorCode,String message)
    static void crashWithInstanceName(String instanceName,Throwable t, String errorCode,String message,String location)
    static void crashWithInstanceName(String instanceName,Throwable t, String errorCode,String message)
    
    // Option setting functions
    static boolean getNeloEnable(String instanceName)
    static void setNeloEnable(String instanceName,boolean enabled)
    
    static boolean getDebug(String instanceName)
    static void setDebug(String instanceName,boolean enabled)
    
    static int getMaxFileSize(String instanceName)
    static void setMaxFileSize(String instanceName,int max_file_size)
    
    static boolean getSendInitLog(String instanceName)
    static void setSendInitLog(String instanceName,boolean enabled)
    
    static Nelo2LogLevel getLogLevelFilter(String instanceName)
    static void setLogLevelFilter(String instanceName,Nelo2LogLevel loglevel)
    
    static void setCrashInstanceName(String name)
    static String getCrashInstanceName()
    

    Effective Log Search & Analytics Android SDK 설치

    다운로드한 Effective Log Search & Analytics Android SDK를 Android 프로젝트의 libs 폴더에 저장합니다.

    NELO SDK 0.9.0 버전부터 프로토콜에 따라 libs 폴더에 추가하는 라이브러리 파일이 다릅니다.

    NELO SDK 필수 추가 항목 nelo2-android-sdk-common-버전명.aar, tink-android-버전명.jar
    --> Thrift 프로토콜 사용시 nelo2-android-sdk-thrift-버전명.aar
    --> HTTPS 프로토콜 사용시 nelo2-android-sdk-https-버전명.aar
    
        .....
        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')
        }
        .....
    

    elsa-1-4-1_ko.png

    [그림 - libs저장된 NELO2 Android SDK]

    Effective Log Search & Analytics NELO Android SDK 설정

    Effective Log Search & Analytics NELO Android SDK 초기화

    Effective Log Search & Analytics Android SDK는 두 가지 방법으로 초기화할 수 있습니다.

    1. init 메서드를 이용한 초기화 방법

      • 기존과 동일하게 앱 크래시 발생 시, Crash Dialog를 생성하지 않고 전송합니다.
      • Activity보다는 Application에서 호출하는 것이 좋습니다.
    2. Application Class에서 @NeloConf 애너테이션과 같이 사용

      • 앱 크래시 발생 시 사용자의 설정에 따라 Crash 로그를 전송하는 Dialog를 출력합니다.

    Main Activity에서 초기화하는 방법

    public class MainActivity extends Activity {
    
        .....
    
        @Override
    
        protected void onCreate(Bundle savedInstanceState) {
    
            .....
    
            NeloLog.init(getApplication(), "elsa-col.ncloud.com", new HTTPSFactory(), "__프로젝트_아이디__", "__프로젝트버전__");
    
            .....
    
        }
    
    }
    

    Application에서 초기화하는 방법

    @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);
            .....
        }
    }
    .....
    

    추가로 AndroidManifest.xml 파일에 권한을 추가해야 합니다. 해당 권한은 네트워크 상태, 디바이스정보, 통신사, Logcat 등의 정보를 가져오기 위해서 필요합니다.

    .....
    /** AndroidManifest.xml **/
        <!-- Nelo 로그 전송을 위한 인터넷 접근 권한(필수) -->
        <uses-permission android:name="android.permission.INTERNET"/>
    
        <!-- Platform, Carrier 등 폰의 정보를 접근하기 위한 권한(필수) -->
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    
        <!-- Network 접근 여부에 대하여 접근하기 위한 권한(필수) -->
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    
        <!-- Network에 접근되지 않는 경우, 파일로 data를 저장하기 위한 권한 -->
        <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" />
    .....
    
          <!-- Crash Report Dialog를 사용하기 위하여 Application을 생성했다면 이름을 설정해야 함-->
           <application ..... android:name="ApplicationName">
    .....
    
           <!-- Network 상태를 체크하여 WiFi 모드일 때만 로그를 보내기 위해서 추가되어야 하는 리시버 -->
        <!-- SendMode를 All로 사용 시는 추가하지 않아도 됨 -->
        <receiver android:name="com.navercorp.nelo2.android.util.NetworkStatusReceiver">
            <intent-filter>
                   <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
            </intent-filter>
        </receiver>
    .....
    
    <!-- Crash Report Dialog를 사용하기 위한 Activity -->
    <!-- CrashReportMode.DIALOG를 사용하지 않으면 추가하지 않아도 됨 -->
    <activity android:name="com.navercorp.nelo2.android.CrashReportDialog"
        android:theme="@android:style/Theme.Dialog"
        android:launchMode="singleInstance"
        android:excludeFromRecents="true"
        android:finishOnTaskLaunch="true" />
    .....
    

    Effective Log Search & Analytics NELO2 Android SDK 사용

    Effective Log Search & Analytics Android SDK를 사용하는 실제 코드 예입니다.

    .....
    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
        }
    .....
    

    NELO2 Android SDK API 상세 정보

    Effective Log Search & Analytics NELO Android SDK에서 제공하는 각 API에 대하여 상세히 설명합니다.

    초기화 함수

    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)
    

    Parameters

    • Application application: Android의 application 정보. 일반적으로 getApplication()을 사용합니다.
    • String reportServer: Effective Log Search & Analytics 수집 서버의 주소
      • Thrift 프로토콜 사용 시
        • Effective Log Search & Analytics 수집 서버: elsa-col.ncloud.com
      • HTTPS 프로토콜 사용 시
        • Effective Log Search & Analytics 수집 서버: https://elsa-col.ncloud.com/_store
    • ProtocolFacotry protocolFactory : 수집 서버의 연결 프로토콜
      • Thrift 프로토콜 사용 시
        • new ThriftFactory()
      • HTTPS 프로토콜 사용 시
        • new HTTPSFactory
    • String appId: Effective Log Search & Analytics에 등록된 프로젝트의 아이디
    • String appVersion: 전송할 앱의 버전 정보
    • String userId: 전송할 사용자 아이디(옵션)

    Example

    NeloLog.init(getApplication(), "elsa-col.ncloud.com", new ThriftFactory(), "72356c50401b8e20_testproject", "1.0.0");
    

    설명

    • NeloLog를 초기화하는 함수. NeloLog를 사용하기 전에 사용되어 NeloLog를 초기화해야 정상 동작합니다. 초기화는 1번만 실행합니다.
    • Activity에서 위 방법으로 초기화 시에는 Crash Report Dialog를 사용할 수 없습니다.

    boolean init (Application application)
    

    Parameters

    • Application application: Android의 Application 정보. 일반적으로 getApplication()을 사용합니다.

    Example

    • 아래와 같이 @NeloConf 애너테이션을 이용하여 다른 항목들을 설정함
    • Activity가 아닌 Application에서 호출하여야 함
    • Crash Report Dialog를 사용하기 위해서는 위 방법으로 초기화하여야만 동작함
    @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);
    
            .....
    
        }
    
    }
    
    .....
    

    설명

    • NeloLog를 초기화하는 함수, @NeloConf 애너테이션과 같이 사용하여야 설정을 할 수 있음
    static void setCrashInstanceName(String instanceName)
    static String getCrashInstanceName()
    

    Example

    NeloLog.setCrashInstanceName("ExampleInstance");
    

    설명

    • When app crashed time, Nelo sdk send crash log to this method setted instance name.
    • Default value : Using NeloLog.init() method (not using instance name method).

    System Field 설정 함수

    static void setUserID(String userID)
    
    static void setUserID(String instanceName, String userID)
    

    Parameters

    • String userID: 사용자 아이디

    Example

    NeloLog.setUserID("test");
    

    설명

    • 사용자 아이디를 설정하기 위하여 사용함. 설정된 값은 이후 보내는 모든 로그에서 동일하게 전달.

    static void setLogSource(String logSource)
    
    static void setLogSource(String instanceName, String logSource)
    

    Parameters

    • String logSource: logSource 정보 설정

    Example

    NeloLog.setLogSource("NELO2 Android SDK LogSource");
    

    설명

    • NELO2의 logSource 정보를 설정하는 API. 설정된 값은 이후 보내는 모든 로그에서 동일하게 전달.

    static void setLogType(String logType)
    
    static void setLogType(String instanceName, String logType)
    

    Parameters

    • String logType: logType 정보 설정

    Example

    NeloLog.setLogType("NELO2 Android SDK LogType");
    

    설명

    • Effective Log Search & Analytics의 logType 정보를 설정하는 API. 설정된 값은 이후 보내는 모든 로그에서 동일하게 전달.

    Custom Field 설정 함수

    static void putCustomMessage(String key, String value)
    static void putCustomMessage(String instanceName, String key, String value)
    

    Parameters

    • String key: 저장할 값의 키
    • String value: 저장 될 값의 값

    Example

    NeloLog.putCustomMessage("test","test value");
    

    설명

    • Custom Message는 키 / 값 형식으로 저장됩니다. 나중에 필드 이름으로 키를 입력합니다.
    • Custom message를 입력하면 이후에 전송되는 모든 로그에서 동일한 사용자 지정 메시지가 전송됩니다.
    static void removeCustomMessage(String key)
    static void removeCustomMessage(String instanceName, String key)
    

    Parameters

    • String key: Key of the field to delete

    Example

    NeloLog.removeCustomMessage("test");
    

    설명

    • 동일한 키를 가진 사용자 Custom message를 삭제합니다.
    static void clearCustomMessage()
    static void clearCustomMessage(String instanceName)
    

    Example

    NeloLog.clearCustomMessage();
    

    설명

    • 설정된 모든 Custom message를 삭제합니다.

    Logcat 설정 함수

    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)
    

    Parameters

    • boolean enabled : Logcat buffer 전송 여부를 설정합니다.

    Example

    NeloLog.setEnableLogcatMain(true);
    

    설명

    • 이 함수는 앱이 Crash 방생 할 때 LogCat buffer 의 각 종류를 전송하도록 활성화 / 비활성화합니다.
    • Logcat에는 기본적으로 세 가지 종류가 있습니다. (Main, Radio, Events)

    Logcat 전송 함수

    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)
    

    Parameters

    • String errorCode: NELO2의 errorCode 필드에 매핑되는 값
    • String message: NELO2의 body에 매핑되는 값
    • String location: Log가 발생한 위치를 입력.

    Example

    NeloLog.sendLogcat("ErrorCode","Message");
    

    설명

    • 이 함수를 사용하여 특정 시간에 Nelo에 logcat buffer를 보냅니다.
    • 이 함수는 setEnableLogcat 함수와 관련이 없습니다.
    • 이 함수는 무거운 작업입니다. 반복해서 콜하지 마세요.

    로그 전송 함수

    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)
    

    Parameters

    • String errorCode: NELO2의 errorCode 필드에 매핑되는 값
    • String message: NELO2의 body에 매핑되는 값
    • String location: Log가 발생한 위치를 입력.

    Example

    NeloLog.error("test","Test value","location");
    NeloLog.debug("test 2","Test value ")
    

    설명

    • Error Level별로 전송하는 함수가 제공됨

    로그 전송 함수(Exception 포함)

    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)
    
    // 동적 인스턴스 로그 전송용
    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)
    

    Parameters

    • Throwable t: Exception 정보
    • String errorCode: Effective Log Search & Analytics의 errorCode 필드에 매핑되는 값
    • String message: Effective Log Search & Analytics의 body에 매핑되는 값
    • String location: Log가 발생한 위치를 입력

    Example

    try{
    
        int a = 10 / 0;
    
    } catch (Exception e) {
    
        NeloLog.error(e,"Error_Code",e.getMessage());
    
    }
    

    설명

    • Error Level별로 전송하는 함수가 제공됨
    • location 정보를 설정하지 않으면, Throwable에서 에러가 발생한 위치를 location에 저장함
    • Throwable 정보를 설정 시 Cause라는 필드가 저장되며, getCause()한 값이 저장됨

    static void crash(Throwable t, String errorCode,String message,String location)
    
    static void crash(Throwable t, String errorCode,String message)
    

    Parameters

    • Throwable t: Exception 정보
    • String errorCode: NELO2의 errorCode 필드에 매핑되는 값
    • String message: NELO2의 body에 매핑되는 값
    • String location: Log가 발생한 위치를 입력

    Example

    try{
        int a = 10 / 0;
    
    } catch (Exception e) {
    
        NeloLog.crash(e,"Error_Code",e.getMessage());
    
    }
    

    설명

    • 사용자가 crash 함수를 호출하는 순간 crash 로그를 Nelo로 전송
    • Crash 로그와 동일하게 DmpData필드 전송
    • 앱의 성능을 위해서 필요한 경우가 아니면 잦은 호출은 피하는것이 좋음

    크래시 콜백

    static void setNeloCrashCallback(NeloCrashCallback neloCrashCallback)
    

    Parameters

    • NeloCrashCallback neloCrashCallback: 크래시 발생 시 호출되는 함수
      • boolean beforeSendNeloCrash()
        • 크래시 발생 시 크래시 로그를 전송할지 말지 return값으로 결정
      • boolean beforeInstanceSendNeloCrash(String instanceName) (현재는 지원하지 않습니다.)
        • 여러 개의 인스턴스를 생성한 경우 특정 인스턴스만 로그를 전송하기 위한다면 instanceName값과 비교해서 return값으로 결정
        • NeloLog.init()로 초기화되는 경우의 이름은 "Nelo2Constants.NELO_DEFAULT_INSTANCE_NAME"으로 사용하면 됩니다.
      • void finishInstanceSendNeloCrash(String instanceName) (현재는 지원하지 않습니다.)
        • 특정 인스턴스의 로그 전송을 마치고 호출되는 함수
      • void finishSendNeloCrash()
        • 전체 크래시 전송을 마치고 호출되는 함수

    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 ]]__________________");
            }
        });
    

    설명

    • 크래시 발생 시 크래시 전송하기 전에 사용자가 정의한 함수를 호출할 수 있는 콜백 함수

    옵션 설정 함수

    static boolean getNeloEnable()
    
    static void setNeloEnable(boolean enabled)
    

    Parameters

    • boolean enabled: Nelo의 사용 여부 설정

    설명

    • false로 설정 시 모든 Nelo의 로그 전송이 중단됨
    • 파일로 저장되는 기능도 동작하지 않음

    static boolean getDebug()
    
    static void setDebug(boolean enabled)
    

    Parameters

    • boolean enabled: Debug 모드의 사용 여부

    설명

    • Debug모드 설정시 Logcat에 자세한 로그를 기록
    • 테스트 환경에서만 true로 설정하고, 운영 환경에서는 false로 설정

    static CrashReportMode getCrashMode()
    
    static void setCrashMode(CrashReportMode mode)
    

    Parameters

    • CrashReportMode mode: 앱 크래시 발생 시 크래시를 전송하는 방법 설정

    설명

    • AndroidManifest.xml 파일의 CrashReportDialog와 연관
    • CrashReportMode
      • CrashReportMode.NONE: 앱 크래시 발생 시 크래시를 전송하지 않음
      • CrashReportMode.SLIENT: 앱 크래시 발생 시 사용자에게 알리지 않고, NELO로 크래시 로그 전송
      • CrashReportMode.DIALOG: 앱 크래시 발생 시 사용자에게 Crash Report Dialog를 보여주고, 사용자가 OK를 선택한 경우만 크래시 전송
        • @NeloConf의 어노테이션의 다음 항목과 연관됨
          • resDialogTitle: Crash Report Dialog의 제목. res/values/string.xml에 정의된 String의 ID
          • resDialogText: Crash Report Dialog의 설명. res/values/string.xml에 정의된 String의 ID

    static NeloSendMode getNeloSendMOde()
    
    static void setNeloSendMOde(NeloSendMode mode)
    

    Parameters

    • NeloSendMode mode: Nelo의 전송방법 설정

    설명

    네트워크 상태ALLONLY_WIFI_WITH_FILE_SAVEONLY_WIFI_WITHOUT_FILE_SAVE
    3g전송미전송, 파일저장미전송, 파일저장 안함
    Wi-FI전송전송전송
    Not Connected미전송, 파일저장미전송, 파일저장미전송, 파일저장안함
    • AndroidManifest.xml 파일의 NetworkStatusReceiver와 연관

    static int getMaxFileSize()
    
    static void setMaxFileSize(int max_file_size)
    
    static int getMaxFileSize(String instanceName)
    
    static void setMaxFileSize(String instanceName, int max_file_size)
    

    Parameters

    • int max_file_size: Nelo에서 저장할 파일의 최고 크기

    설명

    • 기본값은 1Mb(1024 * 1024 byte)
    • 저장되는 값이 max_file_size보다 클 경우, 과거 데이터를 지운 후 저장

    static void flush()
    

    설명

    • 큐와 파일에 저장된 로그를 NELO 서버로 전송함

    static long getAllNeloSaveLogFileSize()
    

    설명

    • 현재 NeloLog가 사용중인 파일의 총 사이즈를 리턴함

    static boolean clearSavedNeloLogFile(boolean flushFile)
    

    Parameters

    • boolean flushFile: 이전 파일을 읽어서 서버로 전송할지 여부를 결정함

    설명

    • 파일명은 InstanceName과 프로젝트명을 가지고 hash하여 생성된 이름으로 사용함
    • 프로젝트명/인스턴스명이 변경되어 기존파일이 삭제가 필요한 경우 위 함수를 호출하면 됨
    • flushFile값이 true이면 이전 파일을 삭제하기 전에 모든 내용을 읽어서 큐에 저장함
    • flushFile의 기본값은 true

    static void setLogLevelFilter(Nelo2LogLevel loglevel)
    static Nelo2LogLevel getLogLevelFilter()
    

    Parameters

    • Nelo2LogLevel loglevel : loglevel 이상의 로그만 Nelo로 전송

    설명

    • 기본값은 Nelo2LogLevel.DEBUG
    • crash 또는 flush 같이 사용자가 명시적으로 로그를 서버로 전송요청하는 경우는 LogLevel 필터의 값을 무시함

    FAQ

    1. Crash 발생 시 파일에 저장된 로그를 모두 Effective Log Search & Analytics 서버로 전송하고 싶다면?

    CrashCallback 함수 중 finishSendNeloCrash() 함수에서 NeloLog.flush()을 호출하여 파일과 큐에 있는 모든 로그를 Nelo 서버로 전송하면 됩니다.

    2. 보낸 적 없는 "New User install App" 로그가 전송됩니다.

    "New User install App" 로그는 App이 최초 인스톨 된 시점에 한 번 전송됩니다.

    3. proguard 적용 시 주의할 점

    proguard 적용 시 ThriftConnector, HttpsConnector도 난독화하면 해당 Class를 찾을 수 없다며 로그 전송에 실패합니다. 이 Class들은 proguard 적용 시 제외 처리해야 합니다.

    4. "Could not find class 'com.nhncorp.nelo2.android.HttpsConnector', referenced from method com.nhncorp.nelo2.android.Nelo2ConnectorFactory.getConnector" 에러가 발생합니다.

    Effective Log Search & Analytics Android SDK 설치과정에서 SDK를 common, thrift, https 이렇게 3개로 나누어 사용한다고 하였는데, https 파트를 추가하지 않는경우 발생하는 경고 문구입니다. thrift로만 전송 시 무시해도 됩니다.


    이 문서가 도움이 되었습니까?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.