ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - SwiftyBeaver/SwiftyBeaver: Convenient & secure logging during development & release in Swift 4 & 5
Convenient & secure logging during development & release in Swift 4 & 5 - SwiftyBeaver/SwiftyBeaver
Visit Site

GitHub - SwiftyBeaver/SwiftyBeaver: Convenient & secure logging during development & release in Swift 4 & 5

GitHub - SwiftyBeaver/SwiftyBeaver: Convenient & secure logging during development & release in Swift 4 & 5


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.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory