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();
Variable | Type | Description | Optional |
---|---|---|---|
shareLogsWithLM | bool | Whether to persist logs locally and send them to the LikeMinds server. | |
onErrorHandler | void Function(Exception, StackTrace) | Callback invoked whenever an exception is handled by the logger. | |
logLevel | Severity | Minimum log severity required for logs to be captured and persisted. | |
coreVersion | String | Optional 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 youronErrorHandler
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);
Variable | Type | Description | Optional |
---|---|---|---|
stackTrace | StackTrace | Stack trace of the log | |
sdkMeta | SDKMeta | SDK metadata | ✔ |
severity | String | Log severity | |
timestamp | int | Log timestamp (unique) |
PushLogRequest
Used to send logs to the server.
PushLogRequest pushLogRequest = (PushLogRequestBuilder()
..logs(lmLogList)).build();
LMResponse response = await loggerApi.pushLogs(request: pushLogRequest);
Variable | Type | Description | Optional |
---|---|---|---|
logs | List<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);
Variable | Type | Description | Optional |
---|---|---|---|
timestamp | int | Logs up to this time are cleared |
Supporting Models
LMLog
Represents a single log entry.
Variable | Type | Description | Optional |
---|---|---|---|
timestamp | int | Timestamp of the log | |
deviceMeta | DeviceDetails | Device information | |
stackTrace | StackTrace | Stack trace | |
sdkMeta | SDKMeta | SDK metadata | ✔ |
severity | Severity | Severity level | ✔ |
DeviceDetails
Holds metadata about the device environment.
Variable | Type | Description | Optional |
---|---|---|---|
versionOs | String | OS version | |
deviceName | String | Device name | |
screenHeight | int | Screen height (pixels) | |
screenWidth | int | Screen width (pixels) | |
wifi | bool | Connected to Wi-Fi or not |
StackTrace
Captures exception and its trace.
Variable | Type | Description | Optional |
---|---|---|---|
exception | String | Exception message | |
trace | String | Stack trace string |
SDKMeta
SDK-specific metadata.
Variable | Type | Description | Optional |
---|---|---|---|
dataLayerVersion | String | Version of data layer | ✔ |
coreVersion | String | Version of core SDK | ✔ |
Severity (Enum)
Levels of severity used for filtering logs.
Severity Level | Description |
---|---|
INFO | General information about app operations, such as initialization or status updates. |
DEBUG | Detailed debug information useful during development or troubleshooting. |
NOTICE | Events that are significant but not errors, such as successful task completions. |
WARNING | Indications of potential issues that do not currently affect functionality. |
ERROR | Errors that have occurred during execution but the app can continue running. |
CRITICAL | Serious issues that may compromise part of the application's functionality. |
ALERT | Events that require immediate attention, possibly affecting core operations. |
EMERGENCY | System-wide failures; the application may not be able to recover. |
DEFAULT | Fallback 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.