Write logging when failed by default
This commit is contained in:
@@ -88,7 +88,7 @@ extension Request {
|
||||
switch val {
|
||||
case "true", "1": return true
|
||||
case "false", "0": return false
|
||||
default: return true
|
||||
default: return false
|
||||
}
|
||||
}
|
||||
public var traceable: Bool { false }
|
||||
@@ -164,12 +164,19 @@ extension Request {
|
||||
return
|
||||
}
|
||||
|
||||
let stringData = String(data: data, encoding: .utf8) ?? ""
|
||||
var stringData = String(data: data, encoding: .utf8) ?? ""
|
||||
|
||||
//print(stringData.prefix(1024))
|
||||
if responseDataLoggable {
|
||||
let logName = "log/\(Date().yyyyMMdd_HHmmssSSSS_forFile)_\(url.lastPathComponent).json"
|
||||
let logUrl = URL.currentDirectory().appending(path: logName)
|
||||
try? stringData.write(toFile: logUrl.path, atomically: false, encoding: .utf8)
|
||||
let responseDataLogging: (String?)->Void = { moreError in
|
||||
if moreError != nil || responseDataLoggable {
|
||||
let logName = "log/\(Date().yyyyMMdd_HHmmssSSSS_forFile)_\(url.lastPathComponent).json"
|
||||
let logUrl = URL.currentDirectory().appending(path: logName)
|
||||
if let moreError = moreError {
|
||||
stringData += "\n\n"
|
||||
stringData += moreError
|
||||
}
|
||||
try? stringData.write(toFile: logUrl.path, atomically: false, encoding: .utf8)
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -177,8 +184,10 @@ extension Request {
|
||||
decoder.keyDecodingStrategy = .useDefaultKeys
|
||||
|
||||
let result = try decoder.decode(KResult.self, from: data)
|
||||
responseDataLogging(nil)
|
||||
completion(.success(result))
|
||||
} catch {
|
||||
responseDataLogging(error.localizedDescription)
|
||||
completion(.failure(error))
|
||||
}
|
||||
}.resume()
|
||||
|
||||
@@ -60,7 +60,7 @@ WIP `showcase` | 추천 상품을 제안함.
|
||||
|
||||
Environment variable | 설명
|
||||
-------------------- | ---
|
||||
KISS_RESPONSE_LOGGABLE | `true`, `1` 이면, API 응답로그를 기록함. `false`, `0` 이면 기록하지 않음.
|
||||
KISS_RESPONSE_LOGGABLE | `true`, `1` 이면, API 응답로그를 기록함. `false`, `0` 이면 기록하지 않음. 기본값은 `false`.
|
||||
|
||||
|
||||
# KissMeIndex
|
||||
|
||||
Reference in New Issue
Block a user