From 02770d91fc9635df6400494f4b2c97e513e39719 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 14 Jun 2021 05:05:34 -0700 Subject: [PATCH] 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. --- Sources/Logging/Logging.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/Logging/Logging.swift b/Sources/Logging/Logging.swift index 9b27a5b..867aa0c 100644 --- a/Sources/Logging/Logging.swift +++ b/Sources/Logging/Logging.swift @@ -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(×tamp) + + var localTime: tm = tm() + _ = _localtime64_s(&localTime, ×tamp) + + _ = strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", &localTime) + #else var timestamp = time(nil) let localTime = localtime(×tamp) 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!)