📣📣 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](#printerviewcontroller) within your app. Printer is using `print` function internally which is more [effective and speedy](https://stackoverflow.com/questions/25951195/swift-print-vs-println-vs-nslog) then `NSLog`.  [](https://travis-ci.org/hemangshah/printer)      [](https://github.com/matteocrippa/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](#printerviewcontroller) only add `Printer.swift`. 2.**CocoaPods**: pod 'printer-logger' 3.**Carthage** [Coming soon]. [Reference](https://medium.com/@filippotosetto/how-to-create-a-carthage-framework-8d9d65f98ac2) > You can read the [CHANGELOG](https://github.com/hemangshah/printer/blob/master/CHANGELOG.md) file for a particular release. ## Features 1. [Different ways to print Logs](#different-ways-to-print-logs) 3. [Plain Logs](#plainlog) 4. [Tracing](#tracing) 5. [All Logs for Print](#all-logs-for-print) 6. [All Logs for Use](#all-logs-for-use) 7. [PrinterViewController](#printerviewcontroller) 7. [Save Logs to a file](#save-logs-to-a-file) 8. [Flush](#flush) 9. [Customize Printer](#customize-printer) 10. [Filter Logs](#filter-logs-filter-by-log-types) 11. [Disable Logs](#disable-logs) 12. [Completion Block](#completion-block) 14. [Background or Foreground Logs](#background-or-foreground-logs) 13. [Shipping to AppStore?](#ready-to-ship-your-app) ## Extras 1. [ToDos](#todos) 2. [Credits](#credits) 3. [Thanks](#thank-you) 4. [License](#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. - [x] 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.
![]() |
![]() |
![]() |