Browse SDKs · uni-app / uni-app x
Platform
SDKsuni-app / uni-app x

Logging and diagnostics

Configure UniApp SDK log levels and upload native diagnostic logs.

Copy

UniApp SDK logs help trace native mobile app initialization, connection lifecycles, and API execution. You can configure log levels, enable standard output logging, and designate native storage directories to accommodate diagnostics across development and production environments.

Configure log levels

Log settings are configured through initialization parameters when calling initSDK():

import {
  OpenIMLogLevelDebug,
  initSDK,
} from '@/uni_modules/unix-openim-sdk'

await initSDK({
  platformID: currentOpenIMPlatform,
  apiAddr,
  wsAddr,
  dataDir: '',
  logFilePath: '',
  logLevel: OpenIMLogLevelDebug,
  isLogStandardOutput: true,
  systemType: 'your-app',
})
Enum valueNumeric valueDescription
OpenIMLogLevelPanic0Catastrophic failures only; terminates the runtime.
OpenIMLogLevelFatal1Fatal crashes and non-recoverable internal errors.
OpenIMLogLevelError2Errors affecting operations; recommended for production troubleshooting.
OpenIMLogLevelWarn3Non-critical warnings; standard for production environments.
OpenIMLogLevelInfo4General lifecycle milestones and connectivity updates.
OpenIMLogLevelDebug5Detailed logs for local development and integration debugging.
OpenIMLogLevelVerbose6Deep diagnostic tracing; avoid leaving enabled long-term in production.

Set isLogStandardOutput to control whether the SDK prints logs to standard output. Use logFilePath to designate the local directory where native logs are written. Ensure this path points to a writable application directory rather than a read-only bundle directory. Refer to Integrate by project and platform for full initialization options.

Upload diagnostic logs

Invoke uploadLogs() to package and transmit locally stored native SDK logs to the log collection service configured for your OpenIM deployment.

Parameters

ParameterTypeRequiredDescription
linenumberYesThe number of recent log lines to collect and upload.
exstringYesAdditional diagnostic context or metadata formatted according to your server deployment conventions.

Code example

import {
  OpenIMUploadLogsProgressEvent,
  off,
  onUploadLogsProgress,
  uploadLogs,
} from '@/uni_modules/unix-openim-sdk'

const handleLogUploadProgress = (
  event: OpenIMUploadLogsProgressEvent | null,
) => {
  if (event == null) return
  setDiagnosticUploadProgress(event.progress)
}

const logUploadSubscription =
  onUploadLogsProgress(handleLogUploadProgress)

await uploadLogs({
  line: 2000,
  ex: 'connection-diagnostic-session',
})

off(logUploadSubscription)

Return value

The returned Promise resolves with a string confirming that the log upload completed successfully. This call does not modify user records, conversations, or messages, nor does it trigger domain events. If the upload fails, the Promise rejects with an error containing errCode and errMsg.

Except for this diagnostics guide, API methods in this SDK do not require client code to generate or pass an operationID. When tracing specific request traces against OpenIMServer logs, diagnostic tools parse the internal identifiers managed by the SDK.