Latest 0.6
Homepage https://github.com/Baconthorpe/LogCountry
License MIT
Platforms ios 9.0
Authors

logo

LogCountry is a simple iOS logging framework written in Swift.

Usage

Logging and Levels

LogCountry’s basic function is simple. Just call the log() function anywhere and pass in something you’d like to be printed.

log("This framework is great!")

You can also set the log level, to filter out messages that aren’t relevant.

Set the level to silent to deactivate all your calls to log(). This will make for a nice, clean console.

setLogLevel(to: .silent)
log("Is this thing on?")  // This message will not appear in the logs.

Set the level to error to print only the most important messages. You can specify error as a message’s level, but log() messages print at that level by default, anyway.

setLogLevel(to: .error)
log(.error, "Do you concur, doctor?")  // This will print.
log("Yes, doctor, I concur.")          // So will this.

Set the level to verbose if you want to see messages that describe the normal operation of a program, as well as error messages.

setLogLevel(.verbose)
log(.verbose, "Loading files...")   // This will print.
log(.error, "Aaand they're gone.")  // So will this.

Set the level to debug if you want all log messages printed.

setLogLevel(.debug)
log(.verbose, "API client initialized.")
log(.debug, "API status normal. Access token = XXXXX")
log(.error, "Uh-oh. Something might be broken.")
log("Yeah, definitely broken. You didn't use the XXXXX placeholder token, did you?")
// These messages will all print.

Specifying log levels for your messages can help you more effectively debug. And LogCountry makes it easy!

Prefixes

Long logs can be hard to read – which message was logged at which level? LogCountry helps you straighten things out by supporting prefixes for each log level.

A log level prefix is a message that precedes every log made at a particular level. By default, the error level has no prefix, but verbose has "VERBOSE: " and debug has "DEBUG: ".

You can set these levels to whatever you prefer.

setLogLevelPrefix(forLevel: .error, to: "ERROR DETECTED - ")
setLogLevelPrefix(forLevel: .verbose, to: "V - ")

log(.error, "No internet.")                 // This will print as 'ERROR DETECTED - No internet.'
log(.verbose, "Searching for internet...")  // This will print as 'V - Searching for internet...'

Modular Logging

What’s that? You don’t like global functions? Paranoid about singletons? Compulsive about modularity?

No problem! You can instantiate a LogCabin that will keep all your level and prefix settings localized.

let uiCabin = LogCabin()
uiCabin.setLogLevelPrefix(forLevel: .debug, to: "UI Debug: ")
uiCabin.level = .debug
uiCabin.log(.debug, "The login screen has appeared.")  // Will print as 'UI Debug: The login screen has appeared.'

Setting up instances of LogCabin can help you make logs specific to each part of an app. They’re also handy if you’re making a framework and want to keep everything in-house.

License

MIT License

Latest podspec

{
    "name": "JSort",
    "version": "0.6",
    "summary": "JSort is a simple framework for parsing JSON data in Swift.",
    "description": "JSort is a simple framework for parsing JSON data in Swift, written by Zeke Abuhoff.",
    "homepage": "https://github.com/Baconthorpe/LogCountry",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Ezekiel Abuhoff": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Baconthorpe/JSort.git",
        "tag": "0.6"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "JSort/*.{swift,plist,h}",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This