0

I am new to XCode and work on Android Studio previously. In Android Studio, there is log cat to log different types of messages for debugging purposes.

Is this available in XCode?

All I found is NSLog which prints the date and the statement without coloring like in log cat. Is there an easier way ?

itsji10dra
  • 4,603
  • 3
  • 39
  • 59
Rashad.Z
  • 2,494
  • 2
  • 27
  • 58
  • Logcat is really a development tool isn't it, grabbing log entries from the device and displaying them on the dev machine. `NSLog()` is similar to how the Android app generates log data. However I don't believe there is anything built into swift, per se, so you'd need to look for generic iOS (Objective-C) solutions. – trojanfoe Nov 03 '15 at 15:32

4 Answers4

2

You can use the print method.

Check out these handy Apple docs.

https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html

joels
  • 1,292
  • 15
  • 21
0

using XCodeColors Library https://github.com/robbiehanson/XcodeColors you can log different types of messages each in a unique color so that you can find error logs faster

also i customized the code like this to get coloring, which class, function, and line number did the call

struct RZLog
{
    static let ESCAPE = "\u{001b}["

    static let RESET_FG = ESCAPE + "fg;" // Clear any foreground color
    static let RESET_BG = ESCAPE + "bg;" // Clear any background color
    static let RESET = ESCAPE + ";"   // Clear any foreground or background color

    static let A = "fg255,0,0;"
    static let B = "fg0,0,255;"
    static let C = "fg16,128,0;"

    static func Error<T>(object: T, filename: String = FILE, line: Int = LINE, funcname: String = FUNCTION) {

        let ClassName = NSURL(string: filename)!
        print("\(ESCAPE)\(A)**ERROR  \(ClassName.lastPathComponent!)(\(line)) Func: \(funcname.uppercaseString):  \(object) **\(RESET)")
    }

    static func Debug<T>(object: T, filename: String = FILE, line: Int = LINE, funcname: String = FUNCTION) {
        let ClassName = NSURL(string: filename)!

        print("\(ESCAPE)\(B)**DEBUG  \(ClassName.lastPathComponent!)(\(line)) Func: \(funcname.uppercaseString):  \(object) **\(RESET)")
    }

    static func VIP<T>(object: T, filename: String = FILE, line: Int = LINE, funcname: String = FUNCTION) {
        let ClassName = NSURL(string: filename)!

        print("\(ESCAPE)\(C)**VIP  \(ClassName.lastPathComponent!)(\(line)) Func: \(funcname.uppercaseString):  \(object) **\(RESET)")
    }
}
Rashad.Z
  • 2,494
  • 2
  • 27
  • 58
0

If you want to use different CocoaLumberjack: https://github.com/CocoaLumberjack/CocoaLumberjack

Which provides some more advantages over simple logging. And it can also be used with colors: http://code.tutsplus.com/tutorials/cocoalumberjack-logging-on-steroids--mobile-15287

Felix Lamouroux
  • 7,414
  • 29
  • 46
0

You can use Printer a new logging experience in Swift 3.x.

It has many functions to add logs in various ways.

Usage:

To log a success message:

Printer.log.success(details: "This is a Success message.")

Output:

Printer ➞ [✅ Success] [⌚04-27-2017 10:53:28] ➞ ✹✹This is a Success message.✹✹
[Trace] ➞ ViewController.swift ➞ viewDidLoad() #58

Disclaimer: This library has been created by me.

Hemang
  • 26,840
  • 19
  • 119
  • 186