Top Related Projects
Dependency injection framework for Swift with iOS/macOS/Linux
A Logging API for Swift
A lightweight, pure-Swift library for downloading and caching images from the web.
Elegant HTTP Networking in Swift
Reactive Programming in Swift
The Swift (and Objective-C) testing framework.
Quick Overview
SwiftyBeaver is a powerful and flexible logging library for Swift applications. It provides colorful, customizable logging functionality for iOS, macOS, tvOS, and watchOS, with support for multiple destinations including console, file, and cloud services.
Pros
- Easy to set up and use with a clean, fluent API
- Supports multiple logging destinations simultaneously
- Offers advanced features like custom formatting, filters, and encryption
- Integrates well with popular development tools and services
Cons
- May be overkill for simple projects with basic logging needs
- Cloud logging service requires a paid subscription for advanced features
- Learning curve for advanced configuration and custom destinations
Code Examples
- Basic logging:
import SwiftyBeaver
let log = SwiftyBeaver.self
log.info("Hello, SwiftyBeaver!")
log.warning("This is a warning")
log.error("An error occurred")
- Setting up multiple destinations:
import SwiftyBeaver
let console = ConsoleDestination()
let file = FileDestination()
SwiftyBeaver.addDestination(console)
SwiftyBeaver.addDestination(file)
let log = SwiftyBeaver.self
log.debug("Logging to console and file")
- Custom formatting:
import SwiftyBeaver
let console = ConsoleDestination()
console.format = "$DHH:mm:ss$d $L $M"
SwiftyBeaver.addDestination(console)
let log = SwiftyBeaver.self
log.info("Custom formatted log message")
Getting Started
To start using SwiftyBeaver in your Swift project:
- Add SwiftyBeaver to your project using Swift Package Manager, CocoaPods, or Carthage.
- Import SwiftyBeaver in your Swift file:
import SwiftyBeaver
let log = SwiftyBeaver.self
// Set up a console destination
let console = ConsoleDestination()
SwiftyBeaver.addDestination(console)
// Start logging
log.verbose("Verbose message")
log.debug("Debug message")
log.info("Info message")
log.warning("Warning message")
log.error("Error message")
This basic setup will log messages to the console. You can add more destinations and customize the logging behavior as needed.
Competitor Comparisons
Dependency injection framework for Swift with iOS/macOS/Linux
Pros of Swinject
- Focused on dependency injection, providing a robust framework for managing object dependencies
- Supports both Swift and Objective-C, making it versatile for iOS development
- Offers advanced features like circular dependencies and object scopes
Cons of Swinject
- Steeper learning curve compared to SwiftyBeaver's straightforward logging functionality
- May introduce additional complexity to smaller projects that don't require extensive dependency management
Code Comparison
Swinject (Dependency Injection):
let container = Container()
container.register(Animal.self) { _ in Cat(name: "Mimi") }
container.register(Person.self) { r in
PetOwner(pet: r.resolve(Animal.self)!)
}
SwiftyBeaver (Logging):
let log = SwiftyBeaver.self
let console = ConsoleDestination()
log.addDestination(console)
log.info("Hello World!")
While Swinject focuses on dependency injection and managing object relationships, SwiftyBeaver is primarily a logging framework. Swinject offers more complex functionality for large-scale application architecture, while SwiftyBeaver provides a simpler, more focused solution for logging needs. The choice between the two depends on the specific requirements of your project.
A Logging API for Swift
Pros of swift-log
- Official Apple project, ensuring long-term support and integration with Swift ecosystem
- Designed for server-side Swift, offering better performance in server environments
- Provides a standardized logging API, promoting consistency across Swift projects
Cons of swift-log
- Less feature-rich compared to SwiftyBeaver, focusing on core logging functionality
- Limited built-in formatters and destinations, requiring additional setup for advanced logging scenarios
- Steeper learning curve for developers accustomed to more opinionated logging frameworks
Code Comparison
SwiftyBeaver:
import SwiftyBeaver
let log = SwiftyBeaver.self
log.info("Hello World")
swift-log:
import Logging
var logger = Logger(label: "com.example.MyApp")
logger.info("Hello World")
Both frameworks offer simple logging capabilities, but SwiftyBeaver provides a more straightforward setup out of the box. swift-log requires explicit logger initialization, which can be beneficial for more granular control in larger applications.
SwiftyBeaver offers additional features like colorized console output and built-in file logging, while swift-log focuses on providing a standardized API that can be extended with custom handlers and formatters.
Ultimately, the choice between these logging frameworks depends on the specific needs of your project, with SwiftyBeaver being more suitable for quick setup and feature-rich logging, and swift-log being ideal for server-side Swift applications and projects requiring a standardized logging approach.
A lightweight, pure-Swift library for downloading and caching images from the web.
Pros of Kingfisher
- Specialized in image downloading and caching, offering robust features for image handling
- Supports various image formats and provides image processing capabilities
- Actively maintained with frequent updates and a large community
Cons of Kingfisher
- Limited to image-related functionality, unlike SwiftyBeaver's broader logging capabilities
- May have a steeper learning curve for developers not familiar with image processing concepts
- Potentially higher memory usage due to image caching mechanisms
Code Comparison
SwiftyBeaver:
import SwiftyBeaver
let log = SwiftyBeaver.self
log.info("Hello World")
Kingfisher:
import Kingfisher
let url = URL(string: "https://example.com/image.png")
imageView.kf.setImage(with: url)
Summary
Kingfisher is a powerful library for image downloading and caching in iOS apps, while SwiftyBeaver focuses on logging and debugging. Kingfisher excels in image-related tasks but is limited to that domain, whereas SwiftyBeaver offers more versatile logging capabilities across different aspects of app development. The choice between the two depends on the specific needs of your project: image handling (Kingfisher) or comprehensive logging (SwiftyBeaver).
Elegant HTTP Networking in Swift
Pros of Alamofire
- More comprehensive networking library with features like request/response serialization, authentication, and parameter encoding
- Wider adoption and larger community support
- Extensive documentation and examples
Cons of Alamofire
- Larger codebase and potentially higher learning curve
- May be overkill for simple logging or debugging tasks
- Focused on networking, not specifically designed for logging
Code Comparison
SwiftyBeaver (Logging):
import SwiftyBeaver
let log = SwiftyBeaver.self
log.info("Hello World")
Alamofire (Networking):
import Alamofire
AF.request("https://api.example.com/data").responseJSON { response in
debugPrint(response)
}
Summary
SwiftyBeaver is a lightweight logging library for Swift, while Alamofire is a comprehensive networking library. SwiftyBeaver excels in simplicity and ease of use for logging purposes, whereas Alamofire provides a robust set of networking features. Choose SwiftyBeaver for straightforward logging needs, and Alamofire for more complex networking requirements in iOS and macOS applications.
Reactive Programming in Swift
Pros of RxSwift
- Powerful reactive programming paradigm for handling asynchronous operations and data streams
- Extensive ecosystem with many extensions and integrations
- Supports complex event-driven architectures and functional programming concepts
Cons of RxSwift
- Steeper learning curve compared to traditional logging libraries
- Can introduce complexity for simpler use cases
- Requires careful management of subscriptions to avoid memory leaks
Code Comparison
SwiftyBeaver (Logging):
import SwiftyBeaver
let log = SwiftyBeaver.self
log.info("Hello World")
RxSwift (Reactive Programming):
import RxSwift
Observable.of("Hello", "World")
.map { $0.uppercased() }
.subscribe(onNext: { print($0) })
.disposed(by: disposeBag)
Summary
SwiftyBeaver is a lightweight logging library for Swift, focusing on simplicity and ease of use for debugging and logging purposes. RxSwift, on the other hand, is a comprehensive reactive programming framework that provides tools for handling asynchronous operations, event streams, and complex data flows.
While SwiftyBeaver excels in its specific domain of logging, RxSwift offers a broader set of capabilities for managing application state and data flow. The choice between the two depends on the project's requirements and complexity. SwiftyBeaver is ideal for straightforward logging needs, while RxSwift is better suited for applications with complex asynchronous operations and event-driven architectures.
The Swift (and Objective-C) testing framework.
Pros of Quick
- Focused on behavior-driven development (BDD) testing framework
- Supports both Swift and Objective-C
- Integrates well with Xcode and other testing tools
Cons of Quick
- Steeper learning curve for developers new to BDD
- May require more setup and configuration compared to traditional unit testing
- Limited to testing scenarios, not suitable for logging or debugging
Code Comparison
Quick:
describe("a calculator") {
it("can add two numbers") {
let calculator = Calculator()
expect(calculator.add(2, 3)).to(equal(5))
}
}
SwiftyBeaver:
let log = SwiftyBeaver.self
log.info("User logged in")
log.warning("Network connection slow")
log.error("Failed to save data")
Key Differences
- Purpose: Quick is a testing framework, while SwiftyBeaver is a logging utility
- Usage: Quick is used for writing and running tests, SwiftyBeaver for logging and debugging
- Integration: Quick integrates with testing workflows, SwiftyBeaver with app runtime
- Language support: Quick works with Swift and Objective-C, SwiftyBeaver is Swift-focused
- Learning curve: Quick may be more complex for beginners, SwiftyBeaver is straightforward
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Colorful, flexible, lightweight logging for Swift 3, Swift 4 & Swift 5.
Great for development & release with support for Console, file & cloud destinations for server-side Swift.
During Development: Colored Logging to Xcode Console via OSLog API or Print
In Xcode 15
// use Apple's fancy OSLog API:
let console = ConsoleDestination()
console.logPrintWay = .logger(subsystem: "Main", category: "UI")
// or use good ol' "print" (which is the default):
let console = ConsoleDestination()
console.logPrintWay = .print
In Xcode 8
Learn more about colored logging to Xcode 8 Console with Swift 3, 4 & 5. For Swift 2.3 use this Gist. No need to hack Xcode 8 anymore to get color. You can even customize the log level word (ATTENTION instead of ERROR maybe?), the general amount of displayed data and if you want to use the ðs or replace them with something else ð
During Development: Colored Logging to File

Learn more about logging to file which is great for Terminal.app fans or to store logs on disk.
Google Cloud & More
You can fully customize your log format, turn it into JSON, or create your own destinations. For example, our Google Cloud Destination is just another customized logging format that adds the powerful functionality of automatic server-side Swift logging when hosted on Google Cloud Platform.
Installation
- For Swift 4 & 5 install the latest SwiftyBeaver version
- For Swift 3 install SwiftyBeaver 1.8.4
- For Swift 2 install SwiftyBeaver 0.7.0
Carthage
You can use Carthage to install SwiftyBeaver by adding that to your Cartfile:
Swift 4 & 5:
github "SwiftyBeaver/SwiftyBeaver"
Swift 3:
github "SwiftyBeaver/SwiftyBeaver" ~> 1.8.4
Swift 2:
github "SwiftyBeaver/SwiftyBeaver" ~> 0.7
Swift Package Manager
For Swift Package Manager add the following package to your Package.swift file. Just Swift 4 & 5 are supported:
.package(url: "https://github.com/SwiftyBeaver/SwiftyBeaver.git", .upToNextMajor(from: "2.0.0")),
CocoaPods
To use CocoaPods just add this to your Podfile:
Swift 4 & 5:
pod 'SwiftyBeaver'
Swift 3:
target 'MyProject' do
use_frameworks!
# Pods for MyProject
pod 'SwiftyBeaver', '~> 1.8.4'
end
Swift 2:
target 'MyProject' do
use_frameworks!
# Pods for MyProject
pod 'SwiftyBeaver', '~> 0.7'
end
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
# Configure Pod targets for Xcode 8 with Swift 2.3
config.build_settings['SWIFT_VERSION'] = '2.3'
end
end
Usage
Add that near the top of your AppDelegate.swift
to be able to use SwiftyBeaver in your whole project.
import SwiftyBeaver
let log = SwiftyBeaver.self
At the beginning of your AppDelegate:didFinishLaunchingWithOptions()
add the SwiftyBeaver log destinations (console, file, etc.), optionally adjust the log format and then you can already do the following log level calls globally:
// add log destinations. at least one is needed!
let console = ConsoleDestination() // log to Xcode Console
let file = FileDestination() // log to default swiftybeaver.log file
// use custom format and set console output to short time, log level & message
console.format = "$DHH:mm:ss$d $L $M"
// or use this for JSON output: console.format = "$J"
// In Xcode 15, specifying the logging method as .logger to display color, subsystem, and category information in the console.(Relies on the OSLog API)
console.logPrintWay = .logger(subsystem: "Main", category: "UI")
// If you prefer not to use the OSLog API, you can use print instead.
// console.logPrintWay = .print
// add the destinations to SwiftyBeaver
log.addDestination(console)
log.addDestination(file)
// Now letâs log!
log.verbose("not so important") // prio 1, VERBOSE in silver
log.debug("something to debug") // prio 2, DEBUG in green
log.info("a nice information") // prio 3, INFO in blue
log.warning("oh no, that wonât be good") // prio 4, WARNING in yellow
log.error("ouch, an error did occur!") // prio 5, ERROR in red
// log anything!
log.verbose(123)
log.info(-123.45678)
log.warning(Date())
log.error(["I", "like", "logs!"])
log.error(["name": "Mr Beaver", "address": "7 Beaver Lodge"])
// optionally add context to a log message
console.format = "$L: $M $X"
log.debug("age", context: 123) // "DEBUG: age 123"
log.info("my data", context: [1, "a", 2]) // "INFO: my data [1, \"a\", 2]"
Alternatively, if you are using SwiftUI, consider using the following setup:
import SwiftyBeaver
let logger = SwiftyBeaver.self
@main
struct yourApp: App {
init() {
let console = ConsoleDestination()
logger.addDestination(console)
// etc...
}
var body: some Scene {
WindowGroup {
}
}
}
Server-side Swift
We â¤ï¸ server-side Swift 4 & 5 and SwiftyBeaver support it out-of-the-box! Try for yourself and run SwiftyBeaver inside a Ubuntu Docker container. Just install Docker and then go to your project folder on macOS or Ubuntu and type:
# create docker image, build SwiftyBeaver and run unit tests
docker run --rm -it -v $PWD:/app swiftybeaver /bin/bash -c "cd /app ; swift build ; swift test"
# optionally log into container to run Swift CLI and do more stuff
docker run --rm -it --privileged=true -v $PWD:/app swiftybeaver
Best: for the popular server-side Swift web framework Vapor you can use our Vapor logging provider which makes server logging awesome again ð
Documentation
Getting Started:
Logging Destinations:
Advanced Topics:
License
SwiftyBeaver Framework is released under the MIT License.
Top Related Projects
Dependency injection framework for Swift with iOS/macOS/Linux
A Logging API for Swift
A lightweight, pure-Swift library for downloading and caching images from the web.
Elegant HTTP Networking in Swift
Reactive Programming in Swift
The Swift (and Objective-C) testing framework.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot