Skip to content

Commit 2de365c

Browse files
authored
Merge pull request #1805 from HaishinKit/feature/srt-logging-interface
Reviewed the class structure of SRTLogger.
2 parents 77474c9 + f601ac6 commit 2de365c

1 file changed

Lines changed: 97 additions & 97 deletions

File tree

Lines changed: 97 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,113 @@
11
import Foundation
22
import libsrt
33

4-
public enum SRTLogLevel: Sendable {
5-
/// Highly detailed and very frequent messages.
6-
case debug
7-
/// Occasionally displayed information.
8-
case notice
9-
/// Unusual behavior.
10-
case warning
11-
/// Abnormal behavior
12-
case error
13-
/// Error that makes the current socket unusabl
14-
case crit
4+
/// An actor for writing interpolated string messages to srt logging system.
5+
public actor SRTLogger {
6+
/// The singleton logger instance.
7+
public static let shared = SRTLogger()
158

16-
var value: Int32 {
17-
switch self {
18-
case .debug:
19-
return LOG_DEBUG
20-
case .notice:
21-
return LOG_NOTICE
22-
case .warning:
23-
return LOG_WARNING
24-
case .error:
25-
return LOG_ERR
26-
case .crit:
27-
return LOG_CRIT
9+
public enum Level: Sendable {
10+
/// Highly detailed and very frequent messages.
11+
case debug
12+
/// Occasionally displayed information.
13+
case notice
14+
/// Unusual behavior.
15+
case warning
16+
/// Abnormal behavior
17+
case error
18+
/// Error that makes the current socket unusabl
19+
case crit
20+
21+
var value: Int32 {
22+
switch self {
23+
case .debug:
24+
return LOG_DEBUG
25+
case .notice:
26+
return LOG_NOTICE
27+
case .warning:
28+
return LOG_WARNING
29+
case .error:
30+
return LOG_ERR
31+
case .crit:
32+
return LOG_CRIT
33+
}
2834
}
2935
}
30-
}
3136

32-
/// Constants that indicate the addition to levels the logging system has functional areas.
33-
public enum SRTLogFunctionalArea: Int32, Sendable {
34-
/// General uncategorized log, for serious issues only
35-
case general = 0
36-
/// Socket create/open/close/configure activities
37-
case bstats = 1
38-
/// Connection establishment and handshake
39-
case control = 2
40-
/// The checkTimer and around activities
41-
case data = 3
42-
/// The TsBPD thread
43-
case tsbpd = 4
44-
/// System resource allocation and management
45-
case rsrc = 5
46-
/// Haicrypt module area
47-
case haicrypt = 6
48-
/// Congestion control module
49-
case congest = 7
50-
/// Packet filter module
51-
case pfilter = 8
52-
/// Applications
53-
case applog
54-
/// API part for socket and library managmenet
55-
case apiCtrl = 11
56-
/// Queue control activities
57-
case queCtrl = 13
58-
/// EPoll, internal update activities
59-
case epollUpd = 16
60-
/// API part for receiving
61-
case apiRecv = 21
62-
/// Buffer, receiving side
63-
case bufRecv = 22
64-
/// Queue, receiving side
65-
case queRecv = 23
66-
/// CChannel, receiving side
67-
case chanRecv = 24
68-
/// Group, receiving side
69-
case grpRecv = 25
70-
/// API part for sending
71-
case apiSend = 31
72-
/// Buffer, sending side
73-
case bufSend = 32
74-
/// Queue, sending side
75-
case queSend = 33
76-
/// CChannel, sending side
77-
case chnSend = 34
78-
/// Group, sending side
79-
case grpSend = 35
80-
/// Internal activities not connected directly to a socket
81-
case `internal` = 41
82-
/// Queue, management part
83-
case queMgmt = 43
84-
/// CChannel, management part
85-
case chnMgmt = 44
86-
/// Group, management part
87-
case grpMgmt = 45
88-
/// EPoll, API part
89-
case epollApi = 46
37+
/// Constants that indicate the addition to levels the logging system has functional areas.
38+
public enum FunctionalArea: Int32, Sendable {
39+
/// General uncategorized log, for serious issues only
40+
case general = 0
41+
/// Socket create/open/close/configure activities
42+
case bstats = 1
43+
/// Connection establishment and handshake
44+
case control = 2
45+
/// The checkTimer and around activities
46+
case data = 3
47+
/// The TsBPD thread
48+
case tsbpd = 4
49+
/// System resource allocation and management
50+
case rsrc = 5
51+
/// Haicrypt module area
52+
case haicrypt = 6
53+
/// Congestion control module
54+
case congest = 7
55+
/// Packet filter module
56+
case pfilter = 8
57+
/// Applications
58+
case applog
59+
/// API part for socket and library managmenet
60+
case apiCtrl = 11
61+
/// Queue control activities
62+
case queCtrl = 13
63+
/// EPoll, internal update activities
64+
case epollUpd = 16
65+
/// API part for receiving
66+
case apiRecv = 21
67+
/// Buffer, receiving side
68+
case bufRecv = 22
69+
/// Queue, receiving side
70+
case queRecv = 23
71+
/// CChannel, receiving side
72+
case chanRecv = 24
73+
/// Group, receiving side
74+
case grpRecv = 25
75+
/// API part for sending
76+
case apiSend = 31
77+
/// Buffer, sending side
78+
case bufSend = 32
79+
/// Queue, sending side
80+
case queSend = 33
81+
/// CChannel, sending side
82+
case chnSend = 34
83+
/// Group, sending side
84+
case grpSend = 35
85+
/// Internal activities not connected directly to a socket
86+
case `internal` = 41
87+
/// Queue, management part
88+
case queMgmt = 43
89+
/// CChannel, management part
90+
case chnMgmt = 44
91+
/// Group, management part
92+
case grpMgmt = 45
93+
/// EPoll, API part
94+
case epollApi = 46
9095

91-
func addLogFA() {
92-
srt_addlogfa(rawValue)
93-
}
96+
func addLogFA() {
97+
srt_addlogfa(rawValue)
98+
}
9499

95-
func delLogFA() {
96-
srt_dellogfa(rawValue)
100+
func delLogFA() {
101+
srt_dellogfa(rawValue)
102+
}
97103
}
98-
}
99-
100-
/// An actor for writing interpolated string messages to srt logging system.
101-
public actor SRTLogger {
102-
/// The singleton logger instance.
103-
public static let shared = SRTLogger()
104104

105105
private init() {
106106
srt_setloglevel(level.value)
107107
}
108108

109109
/// The current logging level.
110-
public private(set) var level: SRTLogLevel = .notice {
110+
public private(set) var level: Level = .notice {
111111
didSet {
112112
guard level != oldValue else {
113113
return
@@ -117,7 +117,7 @@ public actor SRTLogger {
117117
}
118118

119119
/// The current logging functional areas.
120-
public private(set) var functionalAreas: Set<SRTLogFunctionalArea> = [] {
120+
public private(set) var functionalAreas: Set<FunctionalArea> = [] {
121121
didSet {
122122
for area in oldValue.subtracting(functionalAreas) {
123123
area.delLogFA()
@@ -129,12 +129,12 @@ public actor SRTLogger {
129129
}
130130

131131
/// Sets the current logging level.
132-
public func setLevel(_ level: SRTLogLevel) {
132+
public func setLevel(_ level: Level) {
133133
self.level = level
134134
}
135135

136136
/// Sets the current logging functional areas.
137-
public func setFunctionalAreas(_ functionalAreas: Set<SRTLogFunctionalArea>) {
137+
public func setFunctionalAreas(_ functionalAreas: Set<FunctionalArea>) {
138138
self.functionalAreas = functionalAreas
139139
}
140140
}

0 commit comments

Comments
 (0)