JKLoger is a lightweight, high-performance Objective-C logging library designed for iOS applications. It provides multiple log levels, extensible output destinations, customizable formatters, and thread-safe logging capabilities.
🌟 Perfect for production apps - Lightweight, fast, and reliable logging with minimal performance impact.
- 🎯 Multiple Log Levels: Fatal, Error, Warning, Info, Debug with intelligent filtering
- 📤 Extensible Destinations: Console, File, Remote server with custom destination support
- 🎨 Flexible Formatters: Default, Compact, Detailed, JSON, XML, and custom template formatters
- 🔒 Thread-Safe: Asynchronous processing with serial queue for optimal performance
- 🚀 Simple Interface: Convenient macros for easy integration (
JKLogInfo,JKLogError, etc.) - 📱 iOS 13+ Support: Compatible with modern iOS versions and Xcode
- 📦 Package Manager Support: CocoaPods and Swift Package Manager integration
- 🔧 Production Ready: Optimized for performance with comprehensive error handling
- 📊 Rich Metadata: Automatic capture of file, line, function, thread, and timestamp information
- 🌐 Remote Logging: Built-in HTTP-based remote logging with batching and retry logic
在你的 Podfile 中添加:
pod 'JKLoger', '~> 1.0'然后运行:
pod install在 Xcode 中,选择 File > Add Package Dependencies,然后输入:
https://github.com/xingjiahe/JKLoger.git
或者在你的 Package.swift 中添加:
dependencies: [
.package(url: "https://github.com/xingjiahe/JKLoger.git", from: "1.0.0")
]#import <JKLoger/JKLoger.h>
// Use convenient macros for logging
JKLogInfo(@"🚀 Application started");
JKLogError(@"❌ Network error: %@", error);
JKLogDebug(@"🔍 Processing %lu items", (unsigned long)items.count);
JKLogWarning(@"⚠️ Memory usage high: %.1f%%", memoryUsage);
JKLogFatal(@"💀 Critical system failure");- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Configure JKLoger
JKLogger *logger = [JKLogger sharedLogger];
#ifdef DEBUG
logger.logLevel = JKLogLevelDebug;
#else
logger.logLevel = JKLogLevelInfo;
#endif
// Add console output with colors
JKConsoleDestination *console = [[JKConsoleDestination alloc] init];
console.formatter = [JKCustomFormatter colorfulFormatter];
[logger addDestination:console];
// Add file output with JSON format
JKFileDestination *fileDestination = [[JKFileDestination alloc] init];
fileDestination.formatter = [JKCustomFormatter jsonFormatter];
[logger addDestination:fileDestination];
JKLogInfo(@"✅ Logging configured successfully");
return YES;
}// Multiple destinations with different levels
JKLogger *logger = [JKLogger sharedLogger];
// Console: Warnings and above
JKConsoleDestination *console = [[JKConsoleDestination alloc] init];
console.logLevel = JKLogLevelWarning;
console.formatter = [JKCustomFormatter compactFormatter];
[logger addDestination:console];
// File: All messages with detailed format
JKFileDestination *file = [[JKFileDestination alloc] init];
file.maxFileSize = 10 * 1024 * 1024; // 10MB
file.maxFileCount = 5;
file.formatter = [JKCustomFormatter detailedFormatter];
[logger addDestination:file];
// Remote: Only errors with JSON format
NSURL *serverURL = [NSURL URLWithString:@"https://logs.myapp.com/api"];
JKRemoteDestination *remote = [[JKRemoteDestination alloc] initWithServerURL:serverURL];
remote.logLevel = JKLogLevelError;
remote.formatter = [JKCustomFormatter jsonFormatter];
remote.customHeaders = @{@"Authorization": @"Bearer token"};
[logger addDestination:remote];// Create custom format template
NSString *template = @"[{level}] {timestamp} | {file}:{line} | {message}";
JKCustomFormatter *customFormatter = [[JKCustomFormatter alloc] initWithCustomTemplate:template];
// Result: [INFO] 2025-09-29 16:20:30.123 | ViewController.m:42 | User logged in| Document | Description |
|---|---|
| 📖 API Reference | Complete API documentation with examples |
| 🚀 Getting Started | Quick setup guide and basic usage |
| ⚡ Advanced Features | Custom destinations, formatters, and patterns |
| 🔧 Performance Guide | Optimization tips and best practices |
| 📱 Example App | Interactive demo showcasing all features |
| Level | Macro | Description | Use Case |
|---|---|---|---|
| Fatal | JKLogFatal |
Critical system failures | App crashes, data corruption |
| Error | JKLogError |
Error conditions | Network failures, API errors |
| Warning | JKLogWarning |
Potential issues | Deprecated API usage, high memory |
| Info | JKLogInfo |
General information | User actions, app lifecycle |
| Debug | JKLogDebug |
Detailed debugging | Variable values, flow control |
- JKLogger: Main logging manager (singleton pattern)
- JKLogMessage: Log message encapsulation with metadata
- JKConsoleDestination: Console output with color support
- JKFileDestination: File output with rotation and cleanup
- JKRemoteDestination: HTTP-based remote logging
- JKCustomFormatter: Advanced formatting with multiple styles
查看 Example/ 目录中的示例项目,了解如何在实际应用中使用 JKLoger。
cd Example
open JKLogerExample.xcworkspace欢迎贡献代码!请查看 贡献指南 了解详细信息。
JKLoger 使用 MIT 许可证。详情请查看 LICENSE 文件。
xingjiahe - GitHub
查看 CHANGELOG.md 了解版本更新信息。