summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkSwift/SDLLog.swift
blob: 5121d39f2631ba46b722c20b440437985ead3d2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
//  SDLLog.swift
//  SmartDeviceLink-iOS
//
//  Created by Joel Fischer on 3/2/17.
//  Copyright © 2017 smartdevicelink. All rights reserved.
//

import Foundation

import SmartDeviceLink


/// You may use this class or the below functions for convenience logging in Swift 3 projects.
/// It would be used like so:
///
/// ```
/// let log = SDLLog.self
/// log.e("Test something \(NSDate())")
/// ```
public class SDLLog {
    /// Log a verbose message through SDL's custom logging framework.
    ///
    /// - Parameters:
    ///   - message: The message to be logged.
    ///   - file: The file the log is coming from, you should probably leave this as the default.
    ///   - function: The function the log is coming from, you should probably leave this as the default.
    ///   - line: The line the log is coming from, you should probably leave this as the default.
    public class func v(_ message: @autoclosure () -> Any, _ file: String = #file, _ function: String = #function, _ line: Int = #line) {
        SDLLogManager.log(with: .verbose, file: file, functionName: function, line: line, message: "\(message())")
    }

    /// Log a debug message through SDL's custom logging framework.
    ///
    /// - Parameters:
    ///   - message: The message to be logged.
    ///   - file: The file the log is coming from, you should probably leave this as the default.
    ///   - function: The function the log is coming from, you should probably leave this as the default.
    ///   - line: The line the log is coming from, you should probably leave this as the default.
    public class func d(_ message: @autoclosure () -> Any, _ file: String = #file, _ function: String = #function, _ line: Int = #line) {
        SDLLogManager.log(with: .debug, file: file, functionName: function, line: line, message: "\(message())")
    }

    /// Log a warning message through SDL's custom logging framework.
    ///
    /// - Parameters:
    ///   - message: The message to be logged.
    ///   - file: The file the log is coming from, you should probably leave this as the default.
    ///   - function: The function the log is coming from, you should probably leave this as the default.
    ///   - line: The line the log is coming from, you should probably leave this as the default.
    public class func w(_ message: @autoclosure () -> Any, _ file: String = #file, _ function: String = #function, _ line: Int = #line) {
        SDLLogManager.log(with: .warning, file: file, functionName: function, line: line, message: "\(message())")
    }

    /// Log an error message through SDL's custom logging framework.
    ///
    /// - Parameters:
    ///   - message: The message to be logged.
    ///   - file: The file the log is coming from, you should probably leave this as the default.
    ///   - function: The function the log is coming from, you should probably leave this as the default.
    ///   - line: The line the log is coming from, you should probably leave this as the default.
    public class func e(_ message: @autoclosure () -> Any, _ file: String = #file, _ function: String = #function, _ line: Int = #line) {
        SDLLogManager.log(with: .error, file: file, functionName: function, line: line, message: "\(message())")
    }
}

/// Log a verbose message through SDL's custom logging framework.
///
/// - Parameters:
///   - message: The message to be logged.
///   - file: The file the log is coming from, you should probably leave this as the default.
///   - function: The function the log is coming from, you should probably leave this as the default.
///   - line: The line the log is coming from, you should probably leave this as the default.
public func SDLV(_ message: @autoclosure () -> Any, _ file: String = #file, _ function: String = #function, _ line: Int = #line) {
    SDLLogManager.log(with: .verbose, file: file, functionName: function, line: line, message: "\(message())")
}

/// Log a debug message through SDL's custom logging framework.
///
/// - Parameters:
///   - message: The message to be logged.
///   - file: The file the log is coming from, you should probably leave this as the default.
///   - function: The function the log is coming from, you should probably leave this as the default.
///   - line: The line the log is coming from, you should probably leave this as the default.
public func SDLD(_ message: @autoclosure () -> Any, _ file: String = #file, _ function: String = #function, _ line: Int = #line) {
    SDLLogManager.log(with: .debug, file: file, functionName: function, line: line, message: "\(message())")
}

/// Log a warning message through SDL's custom logging framework.
///
/// - Parameters:
///   - message: The message to be logged.
///   - file: The file the log is coming from, you should probably leave this as the default.
///   - function: The function the log is coming from, you should probably leave this as the default.
///   - line: The line the log is coming from, you should probably leave this as the default.
public func SDLW(_ message: @autoclosure () -> Any, _ file: String = #file, _ function: String = #function, _ line: Int = #line) {
    SDLLogManager.log(with: .warning, file: file, functionName: function, line: line, message: "\(message())")
}

/// Log an error message through SDL's custom logging framework.
///
/// - Parameters:
///   - message: The message to be logged.
///   - file: The file the log is coming from, you should probably leave this as the default.
///   - function: The function the log is coming from, you should probably leave this as the default.
///   - line: The line the log is coming from, you should probably leave this as the default.
public func SDLE(_ message: @autoclosure () -> Any, _ file: String = #file, _ function: String = #function, _ line: Int = #line) {
    SDLLogManager.log(with: .error, file: file, functionName: function, line: line, message: "\(message())")
}