Convenient & secure logging during development & release in Swift 3, 4 & 5

Overview

SwiftyBeaver
Colorful, flexible, lightweight logging for Swift 3, Swift 4 & Swift 5.
Great for development & release with support for Console, File & cloud platforms.
Log during release to the conveniently built-in SwiftyBeaver Platform, the dedicated Mac App & Elasticsearch!

Docs | Website | Twitter | Privacy | License

Language Swift 2, 3, 4 & 5 CircleCI



During Development: Colored Logging to Xcode Console

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.


On Release: Encrypted Logging to SwiftyBeaver Platform

Learn more about logging to the SwiftyBeaver Platform during release!


Browse, Search & Filter via Mac App

swiftybeaver-demo1

Conveniently access your logs during development & release with our free Mac App.


On Release: Enterprise-ready Logging to Your Private and Public Cloud

Learn more about legally compliant, end-to-end encrypted logging your own cloud with SwiftyBeaver Enterprise. Install via Docker or manual, fully-featured free trial included!


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 which 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: "1.9.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 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
let cloud = SBPlatformDestination(appID: "foo", appSecret: "bar", encryptionKey: "123") // to cloud

// 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"

// add the destinations to SwiftyBeaver
log.addDestination(console)
log.addDestination(file)
log.addDestination(cloud)

// 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]"


Server-side Swift

We ❤️ server-side Swift 4 & 5 and SwiftyBeaver supports it out-of-the-box! Try for yourself and run SwiftyBeaver inside a Ubuntu Docker container. Just install Docker and then go to your the 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:

Stay Informed:



Privacy

SwiftyBeaver is not collecting any data without you as a developer knowing about it. That's why it is open-source and developed in a simple way to be easy to inspect and check what it is actually doing under the hood.

The only sending to servers is done if you use the SBPlatformDestination. That destination is meant for production logging and on default it sends your logs plus additional device information end-to-end encrypted to our cloud service. Our cloud service can not decrypt the data.

Instead, you install our Mac App and that Mac App downloads the encrypted logs from the cloud and decrypts and shows them to you. Additionally, the Mac App stores all data that it downloads in a local SQLite database file on your computer so that you actually "physically" own your data.

The business model of the SwiftyBeaver cloud service is to provide the most secure logging solution in the market. On purpose we do not provide a web UI for you because it would require us to store your encryption key on our servers.

Only you can see the logging and device data which is sent from your users' devices. Our servers just see encrypted data and do not know your decryption key.

SwiftyBeaver is fully GDPR compliant due to its focus on encryption and transparency in what data is collected and also meets Apple’s latest requirements on the privacy of 3rd party frameworks.

Our Enterprise offering is an even more secure solution where you are not using anymore our cloud service and Mac App but you send your end-to-end encrypted logs directly to your own servers and you store them in your Elasticsearch cluster. The Enterprise offering is used by health tech and governmental institutions which require the highest level of privacy and security.



End-to-End Encryption

SwiftyBeaver is using symmetric AES256CBC encryption in the SBPlatformDestination destination. No other officially supported destination uses encryption.

The encryption used in the SBPlatformDestination destination is end-to-end. The open-source SwiftyBeaver logging framework symmetrically encrypts all logging data on your client's device inside your app (iPhone, iPad, ...) before it is sent to the SwiftyBeaver Crypto Cloud. The decryption is done on your Mac which has the SwiftyBeaver Mac App installed. All logging data stays encrypted in the SwiftyBeaver Crypto Cloud due to the lack of the password.

You are using the encryption at your own risk. SwiftyBeaver’s authors and contributors do not take over any guarantee about the absence of potential security or cryptopgraphy issues, weaknesses, etc.; please also read the LICENSE file for details. Also if you are interested in cryptography in general, please have a look at the file AES256CBC.swift to learn more about the cryptographical implementation.

License

SwiftyBeaver Framework is released under the MIT License.

Comments
  • Colors not showing in Xcode console

    Colors not showing in Xcode console

    Not that this is actually bothering me as I much rather use the tail method in iTerm, but this is still a bug: as stated in the title, colors are not showing in the Xcode console. Instead I get the following:

    [2015-12-16 10:25:20.787] AppDelegate.application(_:didFinishLaunchingWithOptions:):103 g0,0,255;DEBUG[;: something to debug [2015-12-16 10:25:20.790] AppDelegate.application(_:didFinishLaunchingWithOptions:):104 g0,255,0;INFO[;: a nice information [2015-12-16 10:25:20.791] AppDelegate.application(_:didFinishLaunchingWithOptions:):105 g255,255,0;WARNING[;: oh no, that won’t be good [2015-12-16 10:25:20.791] AppDelegate.application(_:didFinishLaunchingWithOptions:):106 g255,0,0;ERROR[;: ouch, an error did occur! [2015-12-16 10:25:20.792] AppDelegate.application(_:didFinishLaunchingWithOptions:):109 g200,200,200;VERBOSE[;: 123 [2015-12-16 10:25:20.792] AppDelegate.application(_:didFinishLaunchingWithOptions:):110 g0,255,0;INFO[;: -123.45678 [2015-12-16 10:25:20.792] AppDelegate.application(_:didFinishLaunchingWithOptions:):111 g255,255,0;WARNING[;: 2015-12-16 09:25:20 +0000 [2015-12-16 10:25:20.792] AppDelegate.application(_:didFinishLaunchingWithOptions:):112 g255,0,0;ERROR[;: ["I", "like", "logs!"] [2015-12-16 10:25:20.835] AppDelegate.application(_:didFinishLaunchingWithOptions:):113 g255,0,0;ERROR[;: ["address": "7 Beaver Lodge", "name": "Mr Beaver"]

    OSX version: el Capitan XCode version: 7.2

    And thanks for a wonderful tool that rocks my world!

    opened by benjaminhorner 25
  • xcodebuild fails on Xcode 12.1 (12A7403) with SwiftyBeaver as a dependency

    xcodebuild fails on Xcode 12.1 (12A7403) with SwiftyBeaver as a dependency

    First of, thanks for the amazing package 😄! Now, installing SwiftyBeaver using the Swift Package manager, as is shown within README fails when invoked through the command line. However, if the project is compiled from within Xcode everything works as expected.

    The steps to reproduce this are fairly simple:

    1. Use Xcode 12.1 (12A7403),
    2. Create a new Swift App,
    3. Add SwiftyBeaver using the Swift Package Manager,
    4. Do the following in the @main - that's the only thing I changed in the whole code generated.
    import SwiftUI
    import SwiftyBeaver
    
    let log = SwiftyBeaver.self
    let console = ConsoleDestination()  // log to Xcode Console
    
    @main
    struct testpackageApp: App {
        let persistenceController = PersistenceController.shared
    
        var body: some Scene {
            WindowGroup {
                ContentView()
                  .environment(\.managedObjectContext, persistenceController.container.viewContext).onAppear {
                    log.addDestination(console)
                    
                    log.info("an example to show it has loaded")
                  }
            }
        }
    }
    

    If I compile within Xcode IDE (even the use of the simulator) everything works as expected; should I go to the command line and type in the directory of the project xcodebuild then it fails with:

    /Users/andylamp/Desktop/testpackage/testpackage/testpackageApp.swift:10:8: error: no such module 'SwiftyBeaver'
    import SwiftyBeaver
           ^
    
    ** BUILD FAILED **
    

    Removing SwiftyBeaver and adding another dependency seems to not generate the same issue (I tried with Alamofire).

    Hope this helps to resolve the issue!

    opened by andylamp 14
  • DO NOT TRUST THIS PROJECT (HACKING POSSIBLE)

    DO NOT TRUST THIS PROJECT (HACKING POSSIBLE)

    In response to @skreutzberger

    Like any other tool, it is up to the developer to ensure that keys are securely stored inside an application or are downloaded from a trusted source during runtime. Also that all has nothing to do with GDPR. Changing the encryption to asymmetric does not make sense since the developer wants to decrypt the logs. There are many other logging frameworks out there in the market so feel free to pick one which fits you better.

    I think you misunderstand how encryption works. Just like with HTTPS, asymmetric encryption does not prevent decrypting the logs by the developer. The developer would hold the private key and the app would have an embedded public key (or an API key which downloads the public key at runtime). This does relate to GDPR since SwiftyBeaver stores data on it's servers and advertises end-to-end encryption. The data stored by SwiftyBeaver has been breached since the private keys are not stored securely. It is akin to setting a password for your email account and then posting the password on Twitter. The email account is no longer secure if the password is publicly available. It is not the responsibility, nor could it be the expectation, of any developer using the SwiftyBeaver service to manually review the encryption algorithm used. It is SwiftyBeaver's responsibility to properly encrypt the data and ensure that no breaches occur (as one has).

    In response to:

    it is up to the developer to ensure that keys are securely stored inside an application or are downloaded from a trusted source during runtime

    There is no possible way to securely download the key since the key is a symmetric key and used for every log. Any mechanism for providing the key to the client to send logs will inherently expose the key to that person to decrypt not just their own logs, but any logs encrypted with that key. The README demonstrates knowledge of this by stating:

    On purpose we do not provide a web UI for you because it would require us to store your encryption key on our servers.

    Only you can see the logging and device data which is sent from your users' devices. Our servers just see encrypted data and do not know your decryption key.

    If it's insecure to store the key on your servers then certainly it is WILDLY INSECURE AND AN ABSOLUTE JOKE OF SECURITY to advertise the encryption key PUBLICLY for all to see in an app binary. This is willful negligence on the part of SwiftyBeaver and must be rectified immediately to avoid penalties under the GDPR which can result in fines up to 10M euros.

    opened by IsaiahJTurner 13
  • wrap swiftyBeaver behind an interface

    wrap swiftyBeaver behind an interface

    I want to have an interface and wrap swiftyBeaver behind the implementation, but when logging the filename and function name used are the once in the implementation class rather than the service logging. How can i make swiftyBeaver log the filename and function name of the service doing the logging?

    opened by Jackbt 13
  • Which Next Custom Destination?

    Which Next Custom Destination?

    Currently SwiftyBeaver supports Xcode Console & file as logging destinations.

    What should be the next destination?

    P.S.: Maybe the destinations should be renamed to beaver lodge - you know, where he brings the logs to :house:

    question 
    opened by skreutzberger 13
  • Remote logging doesn't seem to work on Linux

    Remote logging doesn't seem to work on Linux

    I did have a quick look at the source code and it looks like you're using URLSessionDataTask POST, which is unfortunately broken in Swift foundation implementation https://lists.swift.org/pipermail/swift-corelibs-dev/Week-of-Mon-20160905/000926.html - It assigns an empty request body. It'll be reportedly fixed in Swift 3.1.

    I had experienced the exact same bug and ended up using Vapor's HTTP module for networking instead https://github.com/petrpavlik/PusherNotificationsSwift.

    opened by petrpavlik 12
  • Clickable filenames in logs

    Clickable filenames in logs

    @krzysztofzablocki has a new Xcode plugin for clickable filenames in logs krzysztofzablocki/KZLinkedConsole, and AppCode has that feature too. They use the format filename:line so it would be cool to collaborate and have a default format that has clickable links for those using them.

    in progress 
    opened by samsonjs 12
  • Crash on formatting Date within message

    Crash on formatting Date within message

    I'm using version 1.7.0 of SwiftyBeaver and have not changed versions or made any changes to my apps message formatting recently. Yet in my last release my user's started getting the following crash.

    Screen Shot 2019-08-18 at 2 19 56 PM

    My message formatting string looks like this.

    static func setup() {
            let console = ConsoleDestination()
            console.format = "$DHH:mm:ss.SSS$d $C$L$c $N.$F:$l - $M"
            LogUtils.logger.removeAllDestinations()
            LogUtils.logger.addDestination(console)
        }
    
    opened by mkaminow 11
  • Hiding internal files.

    Hiding internal files.

    Guys, is this possible? My app provides advanced access to the /Dcouments application folder, and Realm, for example, allows to choose which file name should be used. SwiftyBeaver uses file names without leading dot, so it will be visible for app's users.

    What do you suggest to hide your files from user's eyes?

    opened by plasmLC 11
  • forcing the ConsoleDestination to use the main queue

    forcing the ConsoleDestination to use the main queue

    to avoid print() issues..

    About half the time I am seeing ZERO output in my debugger for stuff going to the console.

    I think there are issues with using Swift 'print' outside of the mainq.

    This change just forces the ConsoleDestionation to use the mainq as it's queue.
    This seems to have gotten rid of my 'where are my console logs' problem.

    Also allows people to define their own custom queues for their own Destinations.

    opened by mishagray 11
  • Logical error  in PKCS7.add()

    Logical error in PKCS7.add()

    ` private struct PKCS7 {

    func add(bytes: [UInt8], blockSize: Int) -> [UInt8] {
        let padding = UInt8(blockSize - (bytes.count % blockSize))
        var withPadding = bytes
        if padding == 0 { 
            // If the original data is a multiple of N bytes, then an extra block of bytes with value N is added.
            for _ in 0..<blockSize {
                withPadding.append(contentsOf: [UInt8(blockSize)])
            }
        } else {
            // The value of each added byte is the number of bytes that are added
            for _ in 0..<padding {
                withPadding.append(contentsOf: [UInt8(padding)])
            }
        }
        return withPadding
    }
    

    `

    padding will never be 0... therefore 'if padding == 0' will never be executed.

    For zero-length input additional block will be added

    opened by ladeiko 10
Owner
SwiftyBeaver
The World’s First Logging Platform for Swift
SwiftyBeaver
Customizable login screen, written in Swift 🔶

LFLoginController Customizable login screen, written in Swift Creating Login screens is boring and repetitive. What about implementing and customizing

Awesome Labs 152 Oct 30, 2022
Plug-n-Play login system for iOS written in Swift

Prounounced Cell-Lee Cely’s goal is to add a login system into your app in under 30 seconds! Overview Requirements Usage API Installation License Over

null 164 Nov 15, 2022
Convenient & secure logging during development & release in Swift 3, 4 & 5

Colorful, flexible, lightweight logging for Swift 3, Swift 4 & Swift 5. Great for development & release with support for Console, File & cloud platfor

SwiftyBeaver 5.6k Dec 31, 2022
A logging backend for swift-log that sends logging messages to Logstash (eg. the ELK stack)

LoggingELK LoggingELK is a logging backend library for Apple's swift-log The LoggingELK library provides a logging backend for Apple's apple/swift-log

null 17 Nov 15, 2022
JustLog brings logging on iOS to the next level. It supports console, file and remote Logstash logging via TCP socket with no effort. Support for logz.io available.

JustLog JustLog takes logging on iOS to the next level. It supports console, file and remote Logstash logging via TCP socket with no effort. Support f

Just Eat 509 Dec 10, 2022
Twitter Logging Service is a robust and performant logging framework for iOS clients

Twitter Logging Service Background Twitter created a framework for logging in order to fulfill the following requirements: fast (no blocking the main

Twitter 290 Nov 15, 2022
SecFit (Secure Fitness) is a hybrid mobile application for fitness logging.

SecFit SecFit (Secure Fitness) is a hybrid mobile application for fitness logging. Deploy with Docker Prerequisites: Docker Git Windows hosts must use

Erik Turøy Midtun 0 Oct 22, 2021
Tipsy - Bill splitting and tip calculating App developed during iOS & Swift classes - The Complete App Development Bootcamp

Tipsy ?? Bill splitting and tip calculating App developed during iOS & Swift cla

Rayana Prata 1 Jan 27, 2022
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

Cossack Labs 1.6k Dec 30, 2022
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

Cossack Labs 1.6k Dec 30, 2022
Cybr/Secure - A simple but powerful secure password generator

A simple but powerful secure password generator. You get the option of password length (10 to 20 characters) and whether you include numbers, symbols, uppercase and/or lowercase letters. Simply tap the lock icon to generate a secure password and then tap to copy the password.

Mykel Agathos 1 Feb 16, 2022
GraphQLite is a toolkit to work with GraphQL servers easily. It also provides several other features to make life easier during iOS application development.

What is this? GraphQLite is a toolkit to work with GraphQL servers easily. It also provides several other features to make life easier during iOS appl

Related Code 2.8k Jan 9, 2023
A powerful input-agnostic swift logging framework made to speed up development with maximum readability.

The Swift logging framework. Atlantis is an extremely powerful logging framework that I've created for everyday use, including enterprise development

Andrew Aquino 199 Jan 2, 2023
Repository to store the projects made during the 100 Days of Swift challenge by Paul Hudson of Hacking with Swift.

100DaysOfSwift ?? Repository to store the projects made during the 100 Days of Swift challenge by Paul Hudson of Hacking with Swift. Days 1-12: Introd

Rayana Prata 5 Apr 26, 2022
Library for smooth animation of images during transitions.

ImageTransition ImageTransition is a library for smooth animation of images during transitions. Something looks like below: e.g. UIImageView e.g. UIIm

shtnkgm 207 Dec 3, 2022
Xcode projects and sources created during HWS-Live workshop hosted by @twostraws

Hacking with Swift Live 2021 My Xcode projects and sources created during Hacking With Swift Live online-workshops hosted by @twostraws. Day 1 Various

Philipp 6 May 4, 2022
The code for my CoreGraphics+CoreAnimation talk, held during the 2012 iOS Game Design Seminar at the Technical University Munich.

PKCoreTechniques ======= Core Techniques is the result of a presentation I held at the Technical University of Munich during the 'iOS Game Design Semi

Philip Kluz 143 Sep 21, 2022
A MacOS app created to annoy users so users will go to bed during bedtime hours

A MacOS app created to annoy users so users will go to bed during bedtime hours. Developed for me as a school project.

Helen Dun 1 Jan 17, 2022
This app has always been open source! It began with the Big Brain Hackathon and now during Hacktoberfest

Brain Marks This app has always been open source! It began with the Big Brain Hackathon and now during Hacktoberfest. It is available for free on the

Mikaela Caron 79 Jan 4, 2023
This was built during my bootcamp using SwiftUI, WebKit and an API from Hacker News

HackerNewsReader This was built during my bootcamp using SwiftUI, WebKit and an API from Hacker News. This was programmed from scratch with SwiftUI. I

Wilson Woodyard 2 Feb 25, 2022