-
Notifications
You must be signed in to change notification settings - Fork 3
2. Advanced Usage
Damon东哥 edited this page Mar 25, 2025
·
2 revisions
DDLoggerSwift.isSyncConsole = true
- Default is
true
. - When set to
false
, logs will only be written to the database and will not appear in Xcode’s debug console.
DDLoggerSwift.userID = "0"
- Assigning different
userID
s allows logs to be stored in separate folders. - The default
userID
is0
.
DDLoggerSwift.cleanLog()
- Clears only the displayed logs without deleting log files in the database.
DDLoggerSwift.hide()
DDLoggerSwift.close()
DDLoggerSwift.logExpiryDay = 90
- Default is
90
days. - Set to
0
for unlimited retention. - Log database files are saved per day, and expired logs are automatically deleted.
DDLoggerSwift.deleteLogFile()
- Can delete logs for a specific date.
- If no date is specified, all logs for the current user will be deleted.
Only logs of the selected levels will be saved in the database.
By default, debug logs are not stored.
DDLoggerSwift.storageLevels = [.info, .warn, .error, .privacy]
DDLoggerSwift.DBParentFolder = DDUtils.shared.getFileDirectory(type: .documents)
- By default, logs are stored in the
Documents
folder. - To change the storage location (e.g.,
Caches
folder):
DDLoggerSwift.DBParentFolder = DDUtils.shared.getFileDirectory(type: .caches)
DDLoggerSwift.getAllLog()
- Can fetch logs based on date, keywords, log type, pagination, etc.
DDLoggerSwift.showShare()
- Generates a
DDLoggerSwift.log
file containing the selected date’s logs. - Opens the system share menu to easily share logs via Twitter, WeChat, etc.
Similar to the sharing function:
DDLoggerSwift.showUpload()
- When users confirm the upload, the callback
uploadComplete
is triggered:
DDLoggerSwift.uploadComplete = { file in
print(file)
// Handle file upload
}
DDLoggerSwift.getDBFile(date: Date)
This allows retrieving a log file for a specific date, which can then be uploaded manually.
To access all logs, get the folder containing log database files:
DDLoggerSwift.getDBFolder()
Sorting log files:
let dbFolder = DDLoggerSwift.getDBFolder()
if let enumer = FileManager.default.enumerator(atPath: dbFolder.path) {
while let file = enumer.nextObject() {
if let file: String = file as? String {
if file.hasSuffix(".db") {
// Retrieve the specific log file path
let logFilePath = dbFolder.appendingPathComponent(file, isDirectory: false)
}
}
}
}
SQLite
supports high-concurrency read/write operations without additional configuration.
However, if logs are generated at a very high frequency (e.g., millions per second), throttling can improve efficiency.
DDLoggerSwift.throttleTime = 2
- Default is
0
(no throttling). - A higher value (e.g.,
2
seconds) allows batch writing, which improves performance but introduces a slight delay.
DDLoggerSwift.maxPageSize = 10000
- Default:
10,000
logs per page. - Set to
0
to disable pagination. - If logs exceed millions per day, loading all logs at once can cause delays.
- Enabling pagination improves performance by fetching more logs as the user scrolls.
DDLoggerSwift.cellDisplayCount = 600
- The log viewer automatically adjusts cell height.
- However, very large JSON logs may cause UI lag.
- This setting truncates long logs and provides a "View More" button.