Class ErrorLogHelper


  • public class ErrorLogHelper
    extends java.lang.Object
    ErrorLogHelper to help constructing, serializing, and de-serializing locally stored error logs.
    • Field Detail

      • DEVICE_INFO_FILE

        public static final java.lang.String DEVICE_INFO_FILE
        Device info filename.
        See Also:
        Constant Field Values
      • ERROR_LOG_FILE_EXTENSION

        public static final java.lang.String ERROR_LOG_FILE_EXTENSION
        Error log file extension for the JSON schema.
        See Also:
        Constant Field Values
      • THROWABLE_FILE_EXTENSION

        public static final java.lang.String THROWABLE_FILE_EXTENSION
        Error log file extension for the serialized throwable for client side inspection.
        See Also:
        Constant Field Values
      • FRAME_LIMIT

        public static final int FRAME_LIMIT
        For huge stack traces such as giant StackOverflowError, we keep only beginning and end of frames according to this limit.
        See Also:
        Constant Field Values
      • MAX_PROPERTY_ITEM_LENGTH

        public static final int MAX_PROPERTY_ITEM_LENGTH
        Max length of properties.
        See Also:
        Constant Field Values
      • MINIDUMP_FILE_EXTENSION

        public static final java.lang.String MINIDUMP_FILE_EXTENSION
        Minidump file extension for the NDK crashes.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ErrorLogHelper

        public ErrorLogHelper()
    • Method Detail

      • createErrorLog

        @NonNull
        public static ManagedErrorLog createErrorLog​(@NonNull
                                                     android.content.Context context,
                                                     @NonNull
                                                     java.lang.Thread thread,
                                                     @NonNull
                                                     java.lang.Throwable throwable,
                                                     @NonNull
                                                     java.util.Map<java.lang.Thread,​java.lang.StackTraceElement[]> allStackTraces,
                                                     long initializeTimestamp)
      • createErrorLog

        @NonNull
        public static ManagedErrorLog createErrorLog​(@NonNull
                                                     android.content.Context context,
                                                     @NonNull
                                                     java.lang.Thread thread,
                                                     @NonNull
                                                     Exception exception,
                                                     @NonNull
                                                     java.util.Map<java.lang.Thread,​java.lang.StackTraceElement[]> allStackTraces,
                                                     long initializeTimestamp,
                                                     boolean fatal)
      • getErrorStorageDirectory

        @NonNull
        public static java.io.File getErrorStorageDirectory()
      • getNewMinidumpDirectory

        @NonNull
        public static java.io.File getNewMinidumpDirectory()
        A general folder where unprocessed NDK crashes are saved.
        Returns:
        a folder name e.g. /lib/files/error/minidump/new
      • getNewMinidumpSubfolder

        @NonNull
        public static java.io.File getNewMinidumpSubfolder()
        A one-time run-specific folder where unprocessed NDK crashes are saved.
        Returns:
        a folder name e.g. /lib/files/error/minidump/new/aae16c29-42a9-baee-0777e6ba8fe3
      • getNewMinidumpSubfolderWithContextData

        @NonNull
        public static java.io.File getNewMinidumpSubfolderWithContextData​(android.content.Context context)
        A one-time run-specific folder where unprocessed NDK crashes are saved. Each launch of the application creates its own sub-folder with a random name to store information about the current device (including the application version), which is used in the error report.
        Returns:
        a folder name e.g. /lib/files/error/minidump/new/aae16c29-f9e7-42a9-baee-0777e6ba8fe3
      • getPendingMinidumpDirectory

        @NonNull
        public static java.io.File getPendingMinidumpDirectory()
        A folder where minidumps of processed NDK crashes are saved.
        Returns:
        a folder name e.g. /lib/files/error/minidump/pending
      • getStoredErrorLogFiles

        @NonNull
        public static java.io.File[] getStoredErrorLogFiles()
      • getNewMinidumpFiles

        @NonNull
        public static java.io.File[] getNewMinidumpFiles()
      • getStoredDeviceInfo

        @Nullable
        public static com.microsoft.appcenter.ingestion.models.Device getStoredDeviceInfo​(java.io.File logFolder)
        Get deviceInfo data.
        Parameters:
        logFolder - folder where to look for stored device information.
        Returns:
        a device information or null.
      • getStoredUserInfo

        public static java.lang.String getStoredUserInfo​(java.io.File logFolder)
        Get userId data.
        Parameters:
        logFolder - folder where to look for stored userId.
        Returns:
        userId or null.
      • removeStaleMinidumpSubfolders

        public static void removeStaleMinidumpSubfolders()
        Remove the minidump sub-folders from previous sessions in the 'minidump/new' folder. Minidumps from these folders should already be moved to the 'minidump/pending' folder, so that they can be safely deleted.
      • removeMinidumpFolder

        public static void removeMinidumpFolder()
        Remove the minidump folder.
      • getLastErrorLogFile

        @Nullable
        public static java.io.File getLastErrorLogFile()
      • getStoredThrowableFile

        @Nullable
        public static java.io.File getStoredThrowableFile​(@NonNull
                                                          java.util.UUID id)
      • removeStoredThrowableFile

        public static void removeStoredThrowableFile​(@NonNull
                                                     java.util.UUID id)
      • removeStoredErrorLogFile

        public static void removeStoredErrorLogFile​(@NonNull
                                                    java.util.UUID id)
      • removeLostThrowableFiles

        public static void removeLostThrowableFiles()
        Remove throwable files.
      • getErrorReportFromErrorLog

        @NonNull
        public static ErrorReport getErrorReportFromErrorLog​(@NonNull
                                                             ManagedErrorLog log,
                                                             java.lang.String stackTrace)
      • setErrorLogDirectory

        public static void setErrorLogDirectory​(java.io.File file)
      • getModelExceptionFromThrowable

        @NonNull
        public static Exception getModelExceptionFromThrowable​(@NonNull
                                                               java.lang.Throwable t)
      • validateProperties

        public static java.util.Map<java.lang.String,​java.lang.String> validateProperties​(java.util.Map<java.lang.String,​java.lang.String> properties,
                                                                                                java.lang.String logType)
        Validates properties.
        Parameters:
        properties - Properties collection to validate.
        logType - Log type.
        Returns:
        valid properties collection with maximum size of 5.
      • cleanPendingMinidumps

        public static void cleanPendingMinidumps()
        Clear (delete all content) pending minidump directory.
      • parseLogFolderUuid

        @NonNull
        public static java.util.UUID parseLogFolderUuid​(java.io.File logFolder)
        Parse log folder name UUID. Fallback to random UUID.
        Parameters:
        logFolder - a folder, e.g. lib/files/error/minidump/new/a80da2ae-8c85-43b0-a25b-d52319fb6d56
        Returns:
        parsed UUID or random UUID.
      • clearStaticState

        public static void clearStaticState()