-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData.swift
More file actions
135 lines (125 loc) · 3.78 KB
/
Data.swift
File metadata and controls
135 lines (125 loc) · 3.78 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
MIT License
Original idea/implementation
Copyright (c) 2017 Mladen_K
Adapted and rewritten
Copyright (c) 2020 Zino
*/
import Foundation
/// logger data model
public struct LoggerData : Codable {
/// Default passcode for the lazy (or the developer)
public static let defaultPasscode = "SwiftLoggerPasscode"
/// Standard log types
public enum LoggerType : String, Codable {
/// Debug level message
case DEBUG
/// Info level message
case INFO
/// Warning level message
case WARNING
/// Error level message
case ERROR
}
/// Messages can be directed to the console, a file, or both
public enum LoggerTarget : String, Codable {
/// Write log to disk
case file
/// Show log in UI (including terminal)
case terminal
/// Show and write
case both
}
/// App name, used for naming the file too
public let appName: String
/// Message level
public let logType: LoggerType
/// Message target
public let logTarget: LoggerTarget
/// Source file of origin
public let sourceFile: String
/// Source line of origin
public let lineNumber: Int
/// Source function of origin
public let function: String
/// Text of the message
public let logText: String?
/// Data of the message (eg image, sound, etc)
public let logData: Data?
/// File extension to use when writing that data to disk
public let logDataExt: String?
/// Date of the log, defaults the date of creation
public var logDate: Date = Date()
/// Text message initializer
/// - parameters:
/// - appName: App name, used for naming the file too
/// - logType: Message level
/// - logTarget: Message target
/// - sourceFile: Source file of origin
/// - lineNumber: Source line of origin
/// - function: Source function of origin
/// - logText: Text of the message
public init(
appName apn: String,
logType lty: LoggerType,
logTarget lta: LoggerTarget,
sourceFile sof: String,
lineNumber lin: Int,
function fun: String,
logText text: String
) {
appName = apn
logType = lty
logTarget = lta
sourceFile = sof
lineNumber = lin
function = fun
logText = text
logData = nil
logDataExt = nil
}
/// Data message initializer
/// - parameters:
/// - appName: App name, used for naming the file too
/// - logType: Message level
/// - logTarget: Message target
/// - sourceFile: Source file of origin
/// - lineNumber: Source line of origin
/// - function: Source function of origin
/// - logData: Data of the message (eg image, sound, etc)
/// - dataExtension: File extension to use when writing that data to disk
public init(
appName apn: String,
logType lty: LoggerType,
logTarget lta: LoggerTarget,
sourceFile sof: String,
lineNumber lin: Int,
function fun: String,
logData data: Data,
dataExtension ext: String?
) {
appName = apn
logType = lty
logTarget = lta
sourceFile = sof
lineNumber = lin
function = fun
logText = nil
logData = data
logDataExt = ext
}
}
/// api response data (HTTP only)
public struct LoggerResult : Codable {
/// Status of the response (on top of the http error code)
public enum LoggerStatus : String, Codable {
case ok = "OK"
case error = "ERROR"
}
public let status: LoggerStatus
public let message: String
public init(status sts: LoggerStatus, message msg: String) {
status = sts
message = msg
}
}