A lightweight, level-based logging utility for Swift with bilingual (Chinese/English) documentation.
Supports multiple log levels with emoji indicators, configurable output levels, Unicode decoding for network payloads, and optional file logging with automatic LRU expiration (default: 7 days).
- Add
pod 'Swift_Log'to your Podfile - Run
pod installorpod update - Import with
import Swift_Log
SwiftLog supports SPM. In Xcode: File > Swift Packages > Add Package Dependency, then enter:
https://github.com/zjinhu/SwiftLog
Drag the Sources/SwiftLog folder into your project.
public enum LogDegree: Int {
case trace = 0 // Trace: Track program execution
case debug = 1 // Debug: Debugging information
case net = 2 // Network: Network requests/responses (toggle independently)
case info = 3 // Info: Important information
case warning = 4 // Warning: Warning messages
case error = 5 // Error: Error messages
case fault = 6 // Fault: Critical/fatal errors
}// Set minimum log level (logs below this are ignored)
SLog.defaultLogDegree = .debug
// Toggle network logs independently
SLog.showNetLog = false
// Set max log file age (in seconds), must be set before enabling addFileLog
// Default: 7 days
SLog.maxLogAge = 60 * 60 * 24 * 7
// Enable file logging
SLog.addFileLog = true
// Get log file URL for upload/sharing
SLog.getLogFileURLSLogTrace("Trace level - ignorable details")
SLogDebug("Debug level - development info")
SLogNet("Network payload with \\u6253\\u5370 unicode support")
SLogInfo("Info level - important information")
SLogWarning("Warning level - potential issues")
SLogError("Error level - errors occurred")
SLogFault("Fault level - critical/fatal errors")SLog.trace("Trace message")
SLog.debug("Debug message")
SLog.net("Network message")
SLog.info("Info message")
SLog.warning("Warning message")
SLog.error("Error message")
SLog.fault("Fault message")🌐 Network 🌐 | 2021-03-05 15:27:33:609
所在类:ViewController.swift
方法名:viewDidLoad()
所在行:31
<<<<<<<<<<<<<<<<信息>>>>>>>>>>>>>>>>
netWork
<<<<<<<<<<<<<<<<END>>>>>>>>>>>>>>>>
🔔 Info 🔔 | 2021-03-05 15:27:33:614
所在类:ViewController.swift
方法名:viewDidLoad()
所在行:35
<<<<<<<<<<<<<<<<信息>>>>>>>>>>>>>>>>
info
<<<<<<<<<<<<<<<<END>>>>>>>>>>>>>>>>
⚠️ Warning ⚠️ | 2021-03-05 15:27:33:615
所在类:ViewController.swift
方法名:viewDidLoad()
所在行:38
<<<<<<<<<<<<<<<<信息>>>>>>>>>>>>>>>>
warning
<<<<<<<<<<<<<<<<END>>>>>>>>>>>>>>>>
❌ Error ❌ | 2021-03-05 15:27:33:616
所在类:ViewController.swift
方法名:viewDidLoad()
所在行:41
<<<<<<<<<<<<<<<<信息>>>>>>>>>>>>>>>>
error
<<<<<<<<<<<<<<<<END>>>>>>>>>>>>>>>>
✅ Debug ✅ | 2021-03-05 15:36:57:508
所在类:ViewController.swift
方法名:viewDidLoad()
所在行:28
<<<<<<<<<<<<<<<<信息>>>>>>>>>>>>>>>>
debug
<<<<<<<<<<<<<<<<END>>>>>>>>>>>>>>>>
⚪ Trace ⚪ | 2021-03-05 15:36:57:505
所在类:ViewController.swift
方法名:viewDidLoad()
所在行:25
<<<<<<<<<<<<<<<<信息>>>>>>>>>>>>>>>>
ignore
<<<<<<<<<<<<<<<<END>>>>>>>>>>>>>>>>
SwiftLog provides an AI Skills file for seamless integration with AI coding assistants. See Skills Usage Guide below.
The .skills file contains structured metadata about SwiftLog's API, enabling AI assistants to:
- Auto-suggest correct log functions - AI knows to use
SLogTrace/SLogDebug/SLogNet/SLogInfo/SLogWarning/SLogError/SLogFaultinstead of genericprint() - Apply proper configuration - AI understands
defaultLogDegree,showNetLog,maxLogAge, andaddFileLogsettings - Generate context-aware log messages - AI includes file, function, and line info automatically
When working on a Swift project with SwiftLog installed, you can prompt your AI assistant:
Use SwiftLog to add error handling logs in this function
The AI will automatically generate:
SLogError("Failed to fetch user data: \(error.localizedDescription)")Or for network debugging:
Add network logging to track this API request
The AI will generate:
SLogNet("API Request: \(url) | Method: \(method) | Body: \(body)")Place the SwiftLog.skills file in your project's .opencode/skills/ directory or your global AI assistant skills folder.