Skip to main content

Logging System

The LikeMinds Feed SDK includes a logging system that captures runtime exceptions, SDK metadata, device information, and log severity, and persists this data locally. These logs can be pushed to LikeMinds servers or cleared when required.

Initialization

Before using the logger, initialize it once per app lifecycle:

await LMFeedLogger.instance.initialise(
initiateLoggerRequest: InitiateLoggerRequest(
coreVersion: '1.0.0', //Optional, Should be the correct version of LM Feed Core
logLevel: LMSeverity.ERROR, //Optional
shareLogsWithLM: true,
onErrorHandler: (exception, stackTrace) {
// Custom error handling
},
),
);

Exception Handling

To handle exceptions and automatically log them:

try {
// Code that may throw
} catch (e, st) {
LMFeedLogger.instance.handleException(e, st);
}

You can also specify severity:

LMFeedLogger.instance.handleException(e, st, errorSeverity: LMSeverity.ERROR);

Automatic Log Flush

On app launch or at custom intervals, push logs to the server:

await LMFeedLogger.instance.flushLogs();

Classes and Usage

LMFeedLogger

The main class responsible for:

  • Initializing the logger
  • Handling exceptions
  • Persisting logs locally
  • Pushing logs to the server
  • Clearing logs from local storage

InitiateLoggerRequest

Used to configure and initialize the logging system in the LikeMinds Feed SDK. It determines if logs should be shared with the server, sets the severity threshold for capturing logs, and allows the application to handle exceptions via a callback.

You can build an instance using the builder pattern:

InitiateLoggerRequest loggerRequest = (InitiateLoggerRequestBuilder()
..shareLogsWithLM(true)
..onErrorHandler((e, st) {
// Custom error handler
})
..logLevel(LMSeverity.ERROR)
..coreVersion("1.0.0")) // Optional, Should be the correct version of LM Feed Core
.build();
VariableTypeDescriptionOptional
shareLogsWithLMboolWhether to persist logs locally and send them to the LikeMinds server.
onErrorHandlervoid Function(Exception, StackTrace)Callback invoked whenever an exception is handled by the logger.
logLevelSeverityMinimum log severity required for logs to be captured and persisted.
coreVersionStringOptional version of the core SDK. This is auto-filled internally and should not be manually set unless needed.

Note: If shareLogsWithLM is true, logs will be stored locally and sent to LikeMinds when possible. If false, exceptions will only be passed to your onErrorHandler and will not be recorded.

InsertLogRequest

Used internally to insert logs.

InsertLogRequest insertLogRequest = (InsertLogRequestBuilder()
..stackTrace(stackTrace)
..sdkMeta(lmSdkMeta)
..severity(severityString)
..timestamp(DateTime.now().millisecondsSinceEpoch))
.build();
await logDBHandler!.insertLog(insertLogRequest);
VariableTypeDescriptionOptional
stackTraceStackTraceStack trace of the log
sdkMetaSDKMetaSDK metadata
severityStringLog severity
timestampintLog timestamp (unique)

PushLogRequest

Used to send logs to the server.

PushLogRequest pushLogRequest = (PushLogRequestBuilder()
..logs(lmLogList)).build();
LMResponse response = await loggerApi.pushLogs(request: pushLogRequest);
VariableTypeDescriptionOptional
logsList<LMLog>List of log data

ClearLogRequest

Deletes logs up to a given timestamp.

ClearLogRequest clearLogRequest = (ClearLogRequestBuilder()
..timestamp(DateTime.now().millisecondsSinceEpoch)).build();
await logDBHandler!.clearLogs(clearLogRequest);
VariableTypeDescriptionOptional
timestampintLogs up to this time are cleared

Supporting Models

LMLog

Represents a single log entry.

VariableTypeDescriptionOptional
timestampintTimestamp of the log
deviceMetaDeviceDetailsDevice information
stackTraceStackTraceStack trace
sdkMetaSDKMetaSDK metadata
severitySeveritySeverity level

DeviceDetails

Holds metadata about the device environment.

VariableTypeDescriptionOptional
versionOsStringOS version
deviceNameStringDevice name
screenHeightintScreen height (pixels)
screenWidthintScreen width (pixels)
wifiboolConnected to Wi-Fi or not

StackTrace

Captures exception and its trace.

VariableTypeDescriptionOptional
exceptionStringException message
traceStringStack trace string

SDKMeta

SDK-specific metadata.

VariableTypeDescriptionOptional
dataLayerVersionStringVersion of data layer
coreVersionStringVersion of core SDK

Severity (Enum)

Levels of severity used for filtering logs.

Severity LevelDescription
INFOGeneral information about app operations, such as initialization or status updates.
DEBUGDetailed debug information useful during development or troubleshooting.
NOTICEEvents that are significant but not errors, such as successful task completions.
WARNINGIndications of potential issues that do not currently affect functionality.
ERRORErrors that have occurred during execution but the app can continue running.
CRITICALSerious issues that may compromise part of the application's functionality.
ALERTEvents that require immediate attention, possibly affecting core operations.
EMERGENCYSystem-wide failures; the application may not be able to recover.
DEFAULTFallback level when no specific severity is set; treated as a general log.

Notes

  • The logger only persists logs if shareLogsWithLM is enabled.
  • Logs are pushed to the server with contextual device and SDK metadata.
  • Logs can be manually flushed, cleared, or filtered by severity.