Skip to content

Instantly share code, notes, and snippets.

@r0b0t3d
Forked from cfr/CocoaLumberjack.swift
Last active August 29, 2015 14:10
Show Gist options
  • Save r0b0t3d/723be932a4b26629961f to your computer and use it in GitHub Desktop.
Save r0b0t3d/723be932a4b26629961f to your computer and use it in GitHub Desktop.

CocoaLumberjack.swift

Prerequisites

  • Add CocoaLumberjack 2.0+ in your Podfile, i.e. pod 'CocoaLumberjack', '~> 2.0.0-beta4'.
  • Also import CocoaLumberjack/CocoaLumberjack.h in your bridging header.

Configuring the loggin

  • As usual add all the loggers you might want/need: DDLog.addLogger(DDTTYLogger.sharedInstance())
  • Configure the log level like so: DDLog.logLevel = .Info
  • Log away :)
  • You might also want to enable/disable async logging: DDLog.logAsync = false

License

This Gist is under MIT

// Created by Ullrich Schäfer on 16/08/14.
// Updated to Swift 1.1 and CocoaLumberjack beta4 by Stan Serebryakov on 24/10/14
import Foundation
extension DDLog {
private struct State {
static var logLevel: DDLogLevel = .Error
static var logAsync: Bool = true
}
class var logLevel: DDLogLevel {
get { return State.logLevel }
set { State.logLevel = newValue }
}
class var logAsync: Bool {
get { return (self.logLevel != .Error) && State.logAsync }
set { State.logAsync = newValue }
}
class func log(flag: DDLogFlag, message: @autoclosure () -> String,
function: String = __FUNCTION__, file: String = __FILE__, line: UInt = __LINE__) {
if flag.rawValue & logLevel.rawValue != 0 {
var logMsg = DDLogMessage(message: message(), level: logLevel, flag: flag, context: 0,
file: file, function: function, line: line,
tag: nil, options: DDLogMessageOptions(0), timestamp: nil)
DDLog.log(logAsync, message: logMsg)
}
}
}
func logError(message: @autoclosure () -> String, function: String = __FUNCTION__,
file: String = __FILE__, line: UInt = __LINE__) {
DDLog.log(.Error, message: message, function: function, file: file, line: line)
}
func logWarn(message: @autoclosure () -> String, function: String = __FUNCTION__,
file: String = __FILE__, line: UInt = __LINE__) {
DDLog.log(.Warning, message: message, function: function, file: file, line: line)
}
func logInfo(message: @autoclosure () -> String, function: String = __FUNCTION__,
file: String = __FILE__, line: UInt = __LINE__) {
DDLog.log(.Info, message: message, function: function, file: file, line: line)
}
func logDebug(message: @autoclosure () -> String, function: String = __FUNCTION__,
file: String = __FILE__, line: UInt = __LINE__) {
DDLog.log(.Debug, message: message, function: function, file: file, line: line)
}
func logVerbose(message: @autoclosure () -> String, function: String = __FUNCTION__,
file: String = __FILE__, line: UInt = __LINE__) {
DDLog.log(.Verbose, message: message, function: function, file: file, line: line)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment