Android SDK v3 の使用方法
    • PDF

    Android SDK v3 の使用方法

    • PDF

    Article Summary

    Classic/VPC環境で利用できます。

    Android SDK v3 の使用方法

    概要

    この章では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.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に登録されたプロジェクトのID
    • String appVersion: 転送するアプリのバージョン情報
    • String userId: 転送するユーザーID(オプション)

    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: ユーザーID

    Example

    NeloLog.setUserID("test");
    

    説明

    • ユーザーIDを設定するために使用する。設定された値はその後送信する全てのログで同じく転送。

    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には基本的に3つの種類があります。(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","テスト値","location");
    NeloLog.debug("test 2","テスト値")
    

    説明

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