Skip to content

Commit

Permalink
improve log performance
Browse files Browse the repository at this point in the history
  • Loading branch information
yichengchen committed Apr 7, 2020
1 parent 96a2470 commit ac5f5cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 2 additions & 6 deletions ClashX/Basic/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class Logger {
var fileLogger: DDFileLogger = DDFileLogger()

private init() {
if let tty = DDTTYLogger.sharedInstance {
DDLog.add(tty) // TTY = Xcode console
}
DDLog.add(DDOSLogger.sharedInstance)
fileLogger.rollingFrequency = TimeInterval(60 * 60 * 24) // 24 hours
fileLogger.logFileManager.maximumNumberOfLogFiles = 3
DDLog.add(fileLogger)
Expand All @@ -37,9 +35,7 @@ class Logger {
}

static func log(_ msg: String, level: ClashLogLevel = .info) {
DispatchQueue.global().async {
shared.logToFile(msg: "[\(level.rawValue)] \(msg)", level: level)
}
shared.logToFile(msg: "[\(level.rawValue)] \(msg)", level: level)
}

func logFilePath() -> String {
Expand Down
4 changes: 3 additions & 1 deletion ClashX/General/ApiRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class ApiRequest {

private var proxyRespCache: ClashProxyResp?

private lazy var logQueue = DispatchQueue(label: "com.ClashX.core.log")

private init() {
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 604800
Expand Down Expand Up @@ -293,11 +295,11 @@ extension ApiRequest {

let uriString = "/logs?level=".appending(ConfigManager.selectLoggingApiLevel.rawValue)
let socket = WebSocket(url: URL(string: ConfigManager.apiUrl.appending(uriString))!)

for header in ApiRequest.authHeader() {
socket.request.setValue(header.value, forHTTPHeaderField: header.name)
}
socket.delegate = self
socket.callbackQueue = logQueue
socket.connect()
loggingWebSocket = socket
}
Expand Down

0 comments on commit ac5f5cf

Please sign in to comment.