Logging: avoid a deprecation warning on Windows (#199)

Windows recommends the safety extension usage which in this case
explicitly allow you to be informed of failures.  This just avoids an
annoying warning when using logging in projects.
This commit is contained in:
Saleem Abdulrasool authored and GitHub committed 2021-06-14 21:05:34 +09:00
1 parent 7ebe44cb03
commit 02770d91fc
1 file changed
+10
+10
View File
@@ -1132,9 +1132,19 @@ public struct StreamLogHandler: LogHandler {
private func timestamp() -> String {
var buffer = [Int8](repeating: 0, count: 255)
#if os(Windows)
var timestamp: __time64_t = __time64_t()
_ = _time64(&timestamp)
var localTime: tm = tm()
_ = _localtime64_s(&localTime, &timestamp)
_ = strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", &localTime)
#else
var timestamp = time(nil)
let localTime = localtime(&timestamp)
strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", localTime)
#endif
return buffer.withUnsafeBufferPointer {
$0.withMemoryRebound(to: CChar.self) {
String(cString: $0.baseAddress!)