amplify-swift/Amplify/DevMenu/Data/LogEntryHelper.swift

38 lines
1.1 KiB
Swift

//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
#if canImport(UIKit)
import Foundation
/// Helper class to fetch log entry related information
struct LogEntryHelper {
/// Date formatter instance for date formatting
private static let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSS"
return formatter
}()
/// Helper function to get current time in a specified format
static func dateString(from date: Date) -> String {
return dateFormatter.string(from: date)
}
/// Helper function to fetch logs from `PersistentLoggingPlugin`
static func getLogHistory() -> [LogEntryItem] {
if let loggingPlugin: PersistentLoggingPlugin = Amplify.Logging.plugin as? PersistentLoggingPlugin {
if let logger: PersistentLogWrapper = loggingPlugin.default as? PersistentLogWrapper {
return logger.getLogHistory()
}
}
return [LogEntryItem]()
}
}
#endif