-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Keeper: Nested Shared Folder support and add-account toggles #682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
b6c3e61
84bb85f
690a06e
9c24ef8
9368ed2
ae7e41d
63cda37
b149796
cc140d0
40885a1
cec0504
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Best-effort file log at ~/Library/Logs/iterm2-keeper-adapter.log (stdout is JSON). | ||
|
|
||
| import Foundation | ||
|
|
||
| enum KeeperAdapterLog { | ||
| static let defaultURL: URL = { | ||
| let logsDir = FileManager.default | ||
| .urls(for: .libraryDirectory, in: .userDomainMask) | ||
| .first? | ||
| .appendingPathComponent("Logs") | ||
| let dir = logsDir ?? URL(fileURLWithPath: NSTemporaryDirectory()) | ||
| try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true) | ||
| return dir.appendingPathComponent("iterm2-keeper-adapter.log") | ||
| }() | ||
|
|
||
| static let isEnabled: Bool = { | ||
| ProcessInfo.processInfo.environment["ITERM2_KEEPER_ADAPTER_LOG_DISABLED"] == nil | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logger is enabled by default and writes to a persistent file at
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to opt-in: logging is off by default and enabled with |
||
| }() | ||
|
|
||
| private static let formatter: ISO8601DateFormatter = { | ||
| let f = ISO8601DateFormatter() | ||
| f.formatOptions = [.withInternetDateTime, .withFractionalSeconds] | ||
| return f | ||
| }() | ||
|
|
||
| // Synchronous so short-lived CLI processes do not drop lines on exit. | ||
| private static let lock = NSLock() | ||
|
|
||
| static func write(_ message: String) { | ||
| guard isEnabled else { return } | ||
| let stamp = formatter.string(from: Date()) | ||
| let line = "[\(stamp)] [\(getpid())] \(message)\n" | ||
| guard let data = line.data(using: .utf8) else { return } | ||
| lock.lock() | ||
| defer { lock.unlock() } | ||
| if let handle = try? FileHandle(forWritingTo: defaultURL) { | ||
| defer { try? handle.close() } | ||
| _ = try? handle.seekToEnd() | ||
| try? handle.write(contentsOf: data) | ||
| } else { | ||
| try? data.write(to: defaultURL, options: .atomic) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: this line uses an em dash, which the project style avoids in user-facing text. Could swap it for " - " or reword.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed — replaced the em dash with a period per project style.