mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.5 KiB
Swift
72 lines
2.5 KiB
Swift
//
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
// Once we're on Swift4.2 we can mark this as inlineable
|
|
// @inlinable
|
|
public func owsFormatLogMessage(_ logString: String,
|
|
file: String = #file,
|
|
function: String = #function,
|
|
line: Int = #line) -> String {
|
|
let filename = (file as NSString).lastPathComponent
|
|
// We format the filename & line number in a format compatible
|
|
// with XCode's "Open Quickly..." feature.
|
|
return "[\(filename):\(line) \(function)]: \(logString)"
|
|
}
|
|
|
|
/**
|
|
* A minimal DDLog wrapper for swift.
|
|
*/
|
|
open class Logger: NSObject {
|
|
|
|
open class func verbose(_ logString: @autoclosure () -> String,
|
|
file: String = #file,
|
|
function: String = #function,
|
|
line: Int = #line) {
|
|
#if DEBUG
|
|
let message = owsFormatLogMessage(logString(), file: file, function: function, line: line)
|
|
OWSLogger.verbose(message)
|
|
#endif
|
|
}
|
|
|
|
open class func debug(_ logString: @autoclosure () -> String,
|
|
file: String = #file,
|
|
function: String = #function,
|
|
line: Int = #line) {
|
|
#if DEBUG
|
|
let message = owsFormatLogMessage(logString(), file: file, function: function, line: line)
|
|
OWSLogger.debug(message)
|
|
#endif
|
|
}
|
|
|
|
open class func info(_ logString: String,
|
|
file: String = #file,
|
|
function: String = #function,
|
|
line: Int = #line) {
|
|
let message = owsFormatLogMessage(logString, file: file, function: function, line: line)
|
|
OWSLogger.info(message)
|
|
}
|
|
|
|
open class func warn(_ logString: String,
|
|
file: String = #file,
|
|
function: String = #function,
|
|
line: Int = #line) {
|
|
let message = owsFormatLogMessage(logString, file: file, function: function, line: line)
|
|
OWSLogger.warn(message)
|
|
}
|
|
|
|
open class func error(_ logString: String,
|
|
file: String = #file,
|
|
function: String = #function,
|
|
line: Int = #line) {
|
|
let message = owsFormatLogMessage(logString, file: file, function: function, line: line)
|
|
OWSLogger.error(message)
|
|
}
|
|
|
|
open class func flush() {
|
|
OWSLogger.flush()
|
|
}
|
|
}
|