Swiftpack.co - Package - neilgmacy/SimpleLogging

SimpleLogging

SimpleLogging is a small utility for Swift apps that adds a little more customisation to a basic print statement. You can log at different priority levels, and each level has an emoji to allow for better visual scanning of logs.

Usage

Just import SimpleLogging in the the file where you want to use it, and call the right method for the level you want to log at. For example, if you want to record an error, use Log.error:

import SimpleLogging

func someMethod {
    Log.error("Something went wrong")
}

This will output as below:

2020-02-01 11:31:14 🛑 [ERROR]: Something went wrong

Levels

SimpleLogging has five logging levels. From lowest to highest, they are:

  1. verbose đŸ’Ŧ
  2. debug 👨‍đŸ’ģ
  3. info ℹī¸
  4. warn ⚠ī¸
  5. error 🛑

Configuration Properties

SimpleLogging supports some static configuration properties. It's best to set these properties at an entry point or global configuration point in your app, such as in your AppDelegate.

Minimum logging level

You can set a minimum level to filter out noise. By default this is set to .verbose, meaning all statements will be logged. You can change that easily, for example:

SimpleLogging.minimumLevel = .warn

When the minimum level is warn, any verbose, debug or info statements will be ignored, meaning you only see messages that you have marked as higher priority.

File and Function of call site

You can record in which file and function the print statement took place. This is turned off by default, but is easy to turn on:

SimpleLogging.logFileAndFunction = true

This will add at File: method to the end of your print statements, giving output such as:

2020-02-01 11:31:14 👨‍đŸ’ģ [DEBUG]: configuring tabs at SceneDelegate: configureTabs()

Github

link
Stars: 1

Dependencies

Used By

Total: 0

Releases

v2.0.0: Cleaner API - 2020-02-09 14:56:29

  • Issue https://github.com/neilgmacy/SimpleLogging/issues/5: Makes the API cleaner at the call site
  • Issue https://github.com/neilgmacy/SimpleLogging/issues/4: Use the name SimpleLogging everywhere

1.0.1 - 2020-02-01 15:24:10

Add the MIT license to the project.

- 2020-02-01 12:29:25

Log to Xcode's console with filterable log levels, emojis in logs, optional file and function names, and statements specific to debug and release builds.