Skip to content

Commit 1545e3b

Browse files
author
Arror
committed
Output log to Console.app
1 parent f25305c commit 1545e3b

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

Clash.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@
884884
repositoryURL = "https://github.com/Clash-for-Apple/ClashKit.git";
885885
requirement = {
886886
kind = exactVersion;
887-
version = 1.0.6;
887+
version = 1.0.7;
888888
};
889889
};
890890
/* End XCRemoteSwiftPackageReference section */

CommonKit/ClashLogLevel.swift

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
import Foundation
22

3-
public enum ClashLogLevel: String, Identifiable, CaseIterable {
4-
3+
public enum ClashLogLevel: String, Identifiable, CaseIterable, Comparable {
4+
55
public var id: Self { self }
66

77
case silent, info, debug, warning, error
8+
9+
public static func < (lhs: ClashLogLevel, rhs: ClashLogLevel) -> Bool {
10+
lhs.weight < rhs.weight
11+
}
12+
13+
private var weight: Int {
14+
switch self {
15+
case .silent:
16+
return 0
17+
case .info:
18+
return 1
19+
case .debug:
20+
return 2
21+
case .warning:
22+
return 3
23+
case .error:
24+
return 4
25+
}
26+
}
827
}

PacketTunnel/PacketTunnelProvider+Clash.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ extension PacketTunnelProvider: ClashPacketFlowProtocol, ClashTrafficReceiverPro
4141
}
4242

4343
func log(_ level: String?, payload: String?) {
44-
guard let level = level, let payload = payload else {
44+
guard let level = level.flatMap(ClashLogLevel.init(rawValue:)),
45+
let payload = payload, !payload.isEmpty else {
4546
return
4647
}
47-
NSLog("LEVEL: \(level), PAYLOAD: \(payload)")
48+
NSLog("Clash Core: [\(level.rawValue.uppercased())] \(payload)")
4849
}
4950
}

0 commit comments

Comments
 (0)