feat: add TranscriptionLogger for append-only session log
This commit is contained in:
parent
9ec7b94345
commit
295cd5a500
1 changed files with 27 additions and 0 deletions
27
MyVoxtral/MyVoxtral/Utilities/TranscriptionLogger.swift
Normal file
27
MyVoxtral/MyVoxtral/Utilities/TranscriptionLogger.swift
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import Foundation
|
||||
|
||||
struct TranscriptionLogger {
|
||||
private static var logFileURL: URL {
|
||||
let appSupport = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
|
||||
let dir = appSupport.appendingPathComponent("MyVoxtral", isDirectory: true)
|
||||
try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
||||
return dir.appendingPathComponent("transcription.log")
|
||||
}
|
||||
|
||||
static func append(text: String) {
|
||||
let timestamp = ISO8601DateFormatter().string(from: Date())
|
||||
let entry = "[\(timestamp)]\n\(text)\n---\n\n"
|
||||
|
||||
guard let data = entry.data(using: .utf8) else { return }
|
||||
|
||||
if FileManager.default.fileExists(atPath: logFileURL.path) {
|
||||
if let handle = try? FileHandle(forWritingTo: logFileURL) {
|
||||
handle.seekToEndOfFile()
|
||||
handle.write(data)
|
||||
handle.closeFile()
|
||||
}
|
||||
} else {
|
||||
try? data.write(to: logFileURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue