A fancy logger yet lightweight, and configurable. 🖨

Overview

📣 📣 Important: Printer can only print console logs if you're running an app in the Simulator. If you're running in a real device it will not print any of the logs in console, however, you can always access all logs using PrinterViewController within your app. Printer is using print function internally which is more effective and speedy then NSLog.

Fancy Logo

Build Status License Platform Swift 4.x CocoaPods MadeWithLove Awesome-Swift

You can print the following types of logs with Printer.

  • Success
  • Error
  • 🚧 Warning
  • 📣 Information
  • 🚨 Alert

With each type, it will print a particular emoji and titles which will help you to easily identify what the log is. Moreover, it will look cool too.

Installation

1.Manually - Add Printer folder to your Project. All set. If you don't want PrinterViewController only add Printer.swift.

2.CocoaPods:

pod 'printer-logger'

3.Carthage [Coming soon]. Reference

You can read the CHANGELOG file for a particular release.

Features

  1. Different ways to print Logs
  2. Plain Logs
  3. Tracing
  4. All Logs for Print
  5. All Logs for Use
  6. PrinterViewController
  7. Save Logs to a file
  8. Flush
  9. Customize Printer
  10. Filter Logs
  11. Disable Logs
  12. Completion Block
  13. Background or Foreground Logs
  14. Shipping to AppStore?

Extras

  1. ToDos
  2. Credits
  3. Thanks
  4. License

Let's see what you can do with Printer.

Printer has a singleton, you should always use it with its singleton.

Printer.log.show(id: "001", details: "This is a Success message.", logType: .success)

See the output. Isn't it cool?

[✅ Success] [⌚04-27-2017 10:39:26] [🆔 101] ➞ ✹✹This is a Success message.✹✹

Here are other options you can do with Printer.

Printer.log.show(id: "002", details: "This is a Error message.", logType: .error)
Printer.log.show(id: "003", details: "This is an Information message.", logType: .information)
Printer.log.show(id: "004", details: "This is a Warning message.", logType: .warning)    
Printer.log.show(id: "005", details: "This is an Alert message.", logType: .alert)

Output:

[❌ Error] [⌚04-27-2017 10:41:39] [🆔 102] ➞ ✹✹This is a Error message.✹✹
[🚧 Warning] [⌚04-27-2017 10:41:39] [🆔 103] ➞ ✹✹This is a Warning message.✹✹
[📣 Information] [⌚04-27-2017 10:41:39] [🆔 104] ➞ ✹✹This is an Information message.✹✹
[🚨 Alert] [⌚04-27-2017 10:41:39] [🆔 105] ➞ ✹✹This is an Alert message.✹✹

Different ways to print logs.

Don't want to specify the logType everytime? No problem, we have function for that too.

Printer.log.success(id: "101", details: "This is a Success message. No need to specify logType.")
Printer.log.error(id: "102", details: "This is an Error message. No need to specify logType.")
Printer.log.warning(id: "103", details: "This is a Warning message. No need to specify logType.")
Printer.log.information(id: "104", details: "This is an Information message. No need to specify logType.")
Printer.log.alert(id: "105", details: "This is an Alert message. No need to specify logType.")

Don't want to specify IDs? We have taken care of that too.

Printer.log.success(details: "This is a Success message without ID.")
Printer.log.error(details: "This is an Error message without ID.")
Printer.log.warning(details: "This is a Warning message without ID.")
Printer.log.information(details: "This is an Information message without ID.")
Printer.log.alert(details: "This is an Alert message without ID.")

We have overrided the 'show' function.

Printer.log.show(details: "This is a Success message.", logType: .success)
Printer.log.show(details: "This is an Alert message.", logType: .alert)

Show a future log.

Printer.log.showInFuture(id: "006", details: "This is a future Success message.", logType: .success, afterSeconds: 3)

This will print a log after specified seconds. In this case, success log after three (3) seconds.

plainLog

Don't like the fancy logs? No worries, we have a plain log option.

DEFAULT: false IMPORTANT: Should be called in advance.

Printer.log.plainLog = true

Example when plainLog is set to true.

[04-27-2017 10:50:30] ID ➞ 001 Details ➞ This is a Success message.
[04-27-2017 10:50:30] ID ➞ 002 Details ➞ This is a Error message.
[04-27-2017 10:50:30] ID ➞ 003 Details ➞ This is an Information message.
[04-27-2017 10:50:30] ID ➞ 004 Details ➞ This is a Warning message.
[04-27-2017 10:50:30] ID ➞ 005 Details ➞ This is an Alert message.

We have a new.plain type added with show() function.

Printer.log.show(id: "001", details: "This is a Plain message.", logType: .plain)

This is useful when you only want a few plain logs.

IMPORTANT: Any properties you're setting should be set in advance or before printing any logs to get the exact effect.

SUGGESTION: You can always set all the properties to customize the Printer in AppDelegate.swift file,

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        //set the properties and call the specific function as per the need.

        //Printer.log.plainLog = true
        Printer.log.addLineAfterEachPrint = true
        Printer.log.capitalizeTitles = true
        Printer.log.capitalizeDetails = true
        Printer.log.printOnlyIfDebugMode = true
        
       //Applied filters to only print success and alert type logs.
       //Printer.log.filterLogs = [.success, .alert]
       
        Printer.log.onLogCompletion = { (log) in
          //print(log)
          //print(log.0)
        }

        //Printer.log.hideTitles()
        //Printer.log.hideEmojis()

        return true
    }

This will set the properties globally and will be available for the entire app life cycle.

Tracing

Want to print the file name, function name and line number?

IMPORTANT: Should be call everytime when you want to print a trace.

Printer.log.trace()

Printer.Trace ➞ [05-02-2017 14:58:38] ViewController.swift ➞ viewDidLoad() #40

Auto Tracing

DEFAULT: true IMPORTANT: keepAutoTracing should set to true before logging.

This would print same trace as if you call trace(). If you don't like it, just set keepAutoTracing to false.

All Logs for Print

Want to print all the logs for a different use case?

IMPORTANT: keepTracking should be set to true before logging. Even if keepAutoTracing is set to false; if you pass showTrace to true, you will see the traced info. This is helpful if you don't want to trace while logging.

Printer.log.all(showTrace: true)

[All Logs] [Success] [05-15-2017 14:28:03] Id:001 Details:This is a Success message.
[Trace] ➞ ViewController.swift ➞ viewDidLoad() #58
[All Logs] [Error] [05-15-2017 14:28:03] Id:002 Details:This is a Error message.
[Trace] ➞ ViewController.swift ➞ viewDidLoad() #59
[All Logs] [Information] [05-15-2017 14:28:03] Id:003 Details:This is an Information message.
[Trace] ➞ ViewController.swift ➞ viewDidLoad() #60
[All Logs] [Warning] [05-15-2017 14:28:03] Id:004 Details:This is a Warning message.
[Trace] ➞ ViewController.swift ➞ viewDidLoad() #61
[All Logs] [Alert] [05-15-2017 14:28:03] Id:005 Details:This is an Alert message.
[Trace] ➞ ViewController.swift ➞ viewDidLoad() #62

You can filter them as well.

Printer.log.all(filterLogTypes: [.alert], showTrace: true)

This will only print .alert type tracked logs with tracing info.

[All Logs] [Alert] [05-15-2017 14:28:03] Id:005 Details:This is an Alert message.
[Trace] ➞ ViewController.swift ➞ viewDidLoad() #62

all() function will always print plain logs. No fancy logs.

All Logs for Use

Want to get all the logs?

//let array = Printer.log.getAllLogs()
let array = Printer.log.getAllLogs(filterLogTypes: [.success])
if !array.isEmpty {
    array.forEach({ (log) in
         print(log.details)
        //or do something else.
    })
}

Use cases:

  • To store it somewhere.
  • To make API calls with log details.
  • To do anything which [Printer] isn't supports.

PrinterViewController

See all the printer logs in PrinterViewController. You can also filter the logs within the view controller.

IMPORTANT: PrinterViewController is based on the set properties for Printer and works exactly the same, so please be mindful of the properties that you have set.

Use cases:

  • To see all the logs inside your application while testing the app either on iDevice or a Simulator.
  • No need to check Xcode or Console.

Features:

  • Filter Logs based on types.

  • Copy a particular log.

  • Easy to setup.

  • Search Logs.

[Upcoming]

  • Send a Log file over email.
  • Set Properties within the log file. Example: Plain Log [Switch On/Off] Like that!
  • Clear logs.
  • Air Print.
  • See all the log files.
  • Log files management.
  • Export Text Log files to a PDF.
All Logs No Logs Alert Logs

How to use?

If you prefer manual installation.

You can always use Printer without PrinterViewController. But it's suggestible to add this class for better logging.

  1. Add PrinterTableViewCell.swift, PrinterViewController.swift, Printer.storyboard and Printer.swift in your Project. You can simply add Printer folder as well.
  2. Everything is added, so now copy and paste the code below to present PrinterViewController from your app.

Always add it to someplace (example: navigation bar, side menu, tabbar, app settings) from where you can always present it during development.

    let printerStoryboard = UIStoryboard.init(name: "Printer", bundle: Bundle.main)
    let navcontroller = UINavigationController.init(rootViewController: (printerStoryboard.instantiateViewController(withIdentifier: "PrinterViewControllerID")))
    self.present(navcontroller, animated: true, completion: nil)

Save Logs to a File

Want to create a log file for use? We have covered it too.

let array = Printer.log.getAllLogs()
if !array.isEmpty {    
    Printer.log.saveLogToFile(logs: array)
}        

All your logs will be created in a separate file under Printer folder.

Delete all Log files?

Printer.log.deleteLogFiles()

Flush

Want to delete all the log files and free up some space?

Printer.log.flush()

Customize Printer

You can add a line after each logs.

DEFAULT: false IMPORTANT: Should be called in advance.

Printer.log.addLineAfterEachPrint = true

Example: when addLineAfterEachPrint is set to true.

[✅ Success] [⌚04-27-2017 10:53:28] [🆔 001] ➞ ✹✹This is a Success message.✹✹
________________________________________________________________________________________
[❌ Error] [⌚04-27-2017 10:53:28] [🆔 002] ➞ ✹✹This is a Error message.✹✹
________________________________________________________________________________________
[📣 Information] [⌚04-27-2017 10:53:28] [🆔 003] ➞ ✹✹This is an Information message.✹✹
________________________________________________________________________________________
[🚧 Warning] [⌚04-27-2017 10:53:28] [🆔 004] ➞ ✹✹This is a Warning message.✹✹
________________________________________________________________________________________
[🚨 Alert] [⌚04-27-2017 10:53:28] [🆔 005] ➞ ✹✹This is an Alert message.✹✹
________________________________________________________________________________________

Capitalize Titles & Details

You can even capitalize the title and details of logs.

DEFAULT: false IMPORTANT: Should be called in advance.

Printer.log.capitalizeTitles = true

DEFAULT: false IMPORTANT: Should be called in advance.

Printer.log.capitalizeDetails = true

Example: when capitalizeTitles and capitalizeDetails are set to true.

[✅ SUCCESS] [⌚04-27-2017 11:09:37] [🆔 001] ➞ ✹✹THIS IS A SUCCESS MESSAGE.✹✹

Don't want to show Emojis?

IMPORTANT: Should be called in advance.

Printer.log.hideEmojis()

Example: when hideEmojis() called.

[Success] [04-27-2017 11:08:45] [001] ➞ ✹✹This is a Success message.✹✹
[Error] [04-27-2017 11:08:45] [002] ➞ ✹✹This is a Error message.✹✹
[Information] [04-27-2017 11:08:45] [003] ➞ ✹✹This is an Information message.✹✹
[Warning] [04-27-2017 11:08:45] [004] ➞ ✹✹This is a Warning message.✹✹
[Alert] [04-27-2017 11:08:45] [005] ➞ ✹✹This is an Alert message.✹✹

Don't want to show Titles?

IMPORTANT: Should be called in advance.

Printer.log.hideTitles()

Don't want to show Log Time?

DEFAULT: false IMPORTANT: Should be called in advance.

Printer.log.hideLogsTime = true

Customize Emojis

Don't like the current Emojis? You can override the default Emojis with your favorite Emojis.

IMPORTANT: Should be called in advance.

Printer.log.successEmojiSymbol = "🎃"

Other properties for Emoji customization.

IMPORTANT: Should be called in advance.

Printer.log.errorEmojiSymbol = "<SetNew>"    
Printer.log.warningEmojiSymbol = "<SetNew>"    
Printer.log.infoEmojiSymbol = "<SetNew>"    
Printer.log.alertEmojiSymbol = "<SetNew>"

Customize Titles

Don't like the current Titles or localize Titles? Want to set your own? You can do this.

IMPORTANT: Should be called in advance.

Printer.log.successLogTitle = "Hurray!!"

Other properties for Titles customization.

IMPORTANT: Should be called in advance.

Printer.log.errorLogTitle = "<SetNew>"    
Printer.log.warningLogTitle = "<SetNew>"    
Printer.log.infoLogTitle = "<SetNew>"    
Printer.log.alertLogTitle = "<SetNew>"

Customize Symbols

Don't like the current Symbols? Want to set your own? You can do this.

IMPORTANT: Should be called in advance.

Printer.log.arrowSymbol = "⇨"

Other properties for Symbol customization.

IMPORTANT: Should be called in advance.

Printer.log.starSymbol = "<SetNew>"

Don't like the date format in logs? You can change it too.

DEFAULT: MM-dd-yyyy HH:mm:ss IMPORTANT: Should be called in advance.

Printer.log.logDateFormat = "hh:mm:ss a"

Example when logDateFormat is set to a different format.

[✅ Success] [⌚11:12:23 AM] [🆔 001] ➞ ✹✹This is a Success message.✹✹

Filter Logs: Filter by Log Types

Show specific logs with filter.

Printer.log.filterLogs = [.success, .alert]

This should only print logs of the specified types. I.e. Succes and Alert. All other logs will be ignored.

Filter Logs: Filter by File

Written Printer logs everywhere? Want to Skip logging for LoginViewController.swift for security?

To Skip logs for a file: Printer.log.skipFile() To Add logs for a file: Printer.log.addFile()

IMPORTANT: You should call addFile() to start printing logs for the same file for which you have called skipFile(). This is other than the disable property which completely disables logging for all the files.

Disable Logs

To disable all logs.

DEFAULT: false IMPORTANT: You can set this anywhere and it should not print logs from where it was set.

Printer.log.disable = true

Completion Block

Let you will notified in advance before any logging events.

IMPORTANT: This block will ignore all the filters applied for Printer, meaning, it will always notify you for any logs that will print or not print.

    Printer.log.onLogCompletion = { (log) in
        print(log)
        //print(log.0)
    }

Will return current log, file name, function name, and line number. You can access it with log.0, log.1 and so on.

Use cases:

  • To notify in advance before a log event.
  • To print logs even if you've applied any filter.
  • To call your APIs to store log information. Only code at one place. No dependencies.

You will not get notified if disable is set to true or printOnlyIfDebugMode is set to true and if your app is in release mode.

Background or Foreground Logs

Want to see a log of when your app goes to the background or foreground?

Printer.log.addAppEventsHandler()

[📣 INFORMATION] [⌚05-17-2017 13:17:38]  ➞ ✹✹App is in foreground now.✹✹
________________________________________________________________________________________

Stop logging for background or foreground events?

Printer.log.removeAppEventsHandler()

This is helpful when you're checking all the logs and want to see what happended after app went to background or comes to foreground?

Ready to ship your app?

Don't want to print the logs in RELEASE mode?

DEFAULT: true IMPORTANT: Should be called in advance.

Printer.log.printOnlyIfDebugMode = false

To-Do List

  • Filter Logs.
  • Disable Logs.
  • Manual Tracing.
  • Auto Tracing.
  • All logs - Track all logs and print them all at once.
  • Future Logs – A function which will print a log after a certain time.
  • Skipping logs for a particular file.
  • Delegate calls to let you know the Printer logged.
  • Maintain a log file separately.
  • Improve README file with following: Features List for direct link to a particular point.
  • Log application events. Example: Background/Foreground events.
  • Open a ViewController to show up all the logs.
  • Upcoming features of PrinterViewController.

Have an idea for improvements of this class? Please open an issue.    

Credits

Hemang Shah

You can shoot me an email to contact.  

Thank You!!

See the contributions for details.

License

The MIT License (MIT)

Read the LICENSE file for details.

You might also like...
Simple network activity logger for iOS
Simple network activity logger for iOS

Reqres is a simple library for logging all requests and responses in your app. It supports Alamofire and also requests made via native NSURLSession. ⬆

Stock tradings Logger app for iOS
Stock tradings Logger app for iOS

Stock Logger Contributor: Name: Prof. Darren Takaki Author: Name: Ibrahim (Wusiman Yibulayin) Student ID: 0728356 Table of contents Description Gettin

A simple logger for your swift applications.

AHQSLogger A simple logging system. Usage import AHQSLogger Use the following methods for loggging. Logging an information / debug You can log a simp

An Alamofire network activity logger view
An Alamofire network activity logger view

📒 AlamofireLogbook An Alamofire network activity logger view Installation AlamofireLogbook is available through CocoaPods. To install it, simply add

A fast & simple, yet powerful & flexible logging framework for Mac and iOS
A fast & simple, yet powerful & flexible logging framework for Mac and iOS

CocoaLumberjack CocoaLumberjack is a fast & simple, yet powerful & flexible logging framework for macOS, iOS, tvOS and watchOS. How to get started Fir

CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant
CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant

CleanroomLogger CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant. The API provided by Cleanro

Simple, lightweight and flexible debug logging framework written in Swift

AELog Simple, lightweight and flexible debug logging minion written in Swift If you find yourself in upcoming statements, then you probably want to us

A lightweight logging framework for Swift

HeliumLogger Provides a lightweight logging implementation for Swift which logs to standard output. Features Logs output to stdout by default. You can

A lightweight logging framework for Swift

HeliumLogger Provides a lightweight logging implementation for Swift which logs to standard output. Features Logs output to stdout by default. You can

Comments
  • Edited README.md & CONTRIBUTIONS.md

    Edited README.md & CONTRIBUTIONS.md

    A few things I read are ambiguous to me and I was hoping you can clarify. I'd be happy to push more revisions once I get a better understanding of the lines that need clarification.

    1.Line 118 = “Should be called in advance”? You have a lot of options that you offer your user to customize "Printer", but what do you mean by "Should be called in advance"? Should I call it in the app delegate, viewdidload or should the user set the property prior to get the effect that they want?

    2.Line 433 = “This is other than the disable property which completely disables logging for all the files”?

    3.Line 454 = "Let you will notified in advance before any logging events"?

    4.Line 464 = "Only code at one place"?

    5.Line 486 = "This is helpful when you're checking all the logs and want to see what happended after app went to background or comes to foreground?"

    Cheers!

    enhancement 
    opened by MiguelTepale 2
  • Printer.log.keepAutoTracing = true not working

    Printer.log.keepAutoTracing = true not working

    I have set the keepAutoTracing variable to true and was expecting to get all the functions calls logged automatically without the need to manually call Printer.log.trace() but that is not the case.

    How is it supposed to work?

    Also, I normally need to log the function entry point as well as the exit point. I normally print logs along the line of:

    Myclass.Start(): IN
    ---
    ---
    ---
    ---
    ---
    ---
    Myclass.Start(): OUT
    

    this way I'm able to mentally follow the flow of execution. Is there any way to achieve this behavior with your framework?

    question 
    opened by francobellu 1
Releases(1.4)
Owner
Hemang
iOS Engineer turned to Full Stack
Hemang
A lightweight Swift logger, uses `print` in development and `NSLog` in production. Support colourful and formatted output.

Loggerithm A lightweight Swift logger, uses print in Debug and NSLog in Production with colourful output. Why In Swift, we usually use print to log in

HongHao Zhang 270 Oct 8, 2022
Easy to use and lightweight logger for iOS, macOS, tvOS, watchOS and Linux in Swift.

Lighty Easy to use and lightweight logger for iOS, macOS, tvOS, watchOS and Linux in Swift. Screenshots Requirements Lighty Version Minimum iOS Target

Abdullah Selek 51 Dec 21, 2022
Willow is a powerful, yet lightweight logging library written in Swift.

Willow Willow is a powerful, yet lightweight logging library written in Swift. Features Requirements Migration Guides Communication Installation Cocoa

Nike Inc. 1.3k Nov 16, 2022
A custom logger implementation and Task Local helper for swift-log

LGNLog A custom logger implementation and TaskLocal helper for Swift-Log. Why and how This package provides two and a half things (and a small bonus):

17:11 Games 0 Oct 26, 2021
A network logger for iOS and macOS projects.

OkLog for iOS and macOS OkLog-Swift is a network logger written in Swift highly inspired by simonpercic's original OkLog implementation to be used in

Diego Trevisan Lara 18 Dec 24, 2021
Tracker - A simple location logger app written in Swift and MVVM architecture

Tracker - A simple location logger app written in Swift and MVVM architecture

Loay Ashraf 1 Mar 12, 2022
TraceLog is a highly configurable, flexible, portable, and simple to use debug logging system for Swift and Objective-C applications running on Linux, macOS, iOS, watchOS, and tvOS.

Please star this github repository to stay up to date. TraceLog Introduction TraceLog is a highly configurable, flexible, portable, and simple to use

Tony Stone 52 Oct 28, 2022
Bugfender SDK for iOS, a remote logger tailor-made for mobile

Bugfender SDK for iOS Bugfender is a cloud service to collect mobile application logs. Developers can control log sending programmatically and manuall

Bugfender 69 Dec 4, 2022
LogDog is designed to work out of the box, you can use the pre-configured logger anytime, anywhere

LogDog user-friendly logging apple/swift-log api compatible Usage LogDog is designed to work out of the box, you can use the pre-configured logger any

Luo Xiu 21 Aug 14, 2022
Logger for Xcode

CSwiftLog Usage Log.log("Message text without category") Log.my.log("Message text with custom category") Log.network.log("Message text with network ca

Andrew Firsenko 2 Nov 29, 2021