You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.4 KiB
65 lines
2.4 KiB
//
|
|
// Logger.swift
|
|
// Poker Analytics 4
|
|
//
|
|
// Created by Laurent Morvillier on 29/03/2018.
|
|
//
|
|
|
|
import Foundation
|
|
#if !DEBUG
|
|
//import Firebase
|
|
#endif
|
|
|
|
@objc public class Logger : NSObject {
|
|
|
|
@objc static public func log(_ message: Any, file: String = #file, function: String = #function, line: Int = #line) {
|
|
let filestr: NSString = NSString(string: file)
|
|
print("\(filestr.lastPathComponent).\(line).\(function): \(message)")
|
|
}
|
|
|
|
// @objc static public func error(_ error: Error, file: String = #file, function: String = #function, line: Int = #line) {
|
|
// Logger.error(error, file: file, function: function, line: line)
|
|
// }
|
|
|
|
static public func error(_ error: Error, file: String = #file, function: String = #function, line: Int = #line) {
|
|
let filestr: NSString = NSString(string: file)
|
|
var fireBaseError: Error {
|
|
if let customError = error as? CustomNSError & LocalizedError {
|
|
return customError.fireBaseError
|
|
} else {
|
|
return error
|
|
}
|
|
}
|
|
print("ERROR: \(filestr.lastPathComponent).\(line).\(function): \(fireBaseError)")
|
|
}
|
|
|
|
@objc static public func w(_ message: Any, file: String = #file, function: String = #function, line: Int = #line) {
|
|
let filestr: NSString = NSString(string: file)
|
|
print("!!! Warning !!! \(filestr.lastPathComponent).\(line).\(function): \(message)")
|
|
}
|
|
|
|
@objc static public func crashLogging(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
|
|
let fileName: String = file.components(separatedBy: "/").last ?? file
|
|
#if DEBUG
|
|
NSLogv("%@.%i.%@: %@", getVaList([fileName, line, function, message]))
|
|
#else
|
|
//Crashlytics.crashlytics().log(format: "%@.%i.%@: %@", arguments: getVaList([fileName, line, function, message]))
|
|
#endif
|
|
}
|
|
|
|
}
|
|
|
|
extension LocalizedError where Self: CustomNSError {
|
|
var simpleErrorDescription: String {
|
|
let mirror = Mirror(reflecting: self)
|
|
if let label = mirror.children.first?.label {
|
|
return label
|
|
} else {
|
|
return String(describing:self)
|
|
}
|
|
}
|
|
|
|
var fireBaseError: NSError {
|
|
NSError(domain: Self.errorDomain + "." + self.simpleErrorDescription, code: self.errorCode, userInfo: self.errorUserInfo)
|
|
}
|
|
}
|
|
|