-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iOS Example]: Adding logger override example + Updating file headers (…
- Loading branch information
Showing
6 changed files
with
97 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
mobileChatExamples/iOSChatExample/AmazonConnectChatIOSDemo/Models/CustomLogger.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT-0 | ||
|
||
import Foundation | ||
import AmazonConnectChatIOS | ||
|
||
class CustomLogger: SDKLoggerProtocol { | ||
private var outputDir: URL | ||
private var loggerCreationDateAndTime: String | ||
|
||
init() { | ||
self.outputDir = FileManager.default.temporaryDirectory | ||
|
||
let currentDate = Date() | ||
let dateFormatter = DateFormatter() | ||
dateFormatter.dateFormat = "yyyy-MM-dd_HH-mm" | ||
self.loggerCreationDateAndTime = dateFormatter.string(from: currentDate) | ||
} | ||
|
||
func logVerbose(_ message: @autoclosure () -> String) { | ||
let logMessage = "VERBOSE: \(message())" | ||
print(logMessage) | ||
writeToAppTempFile(content: logMessage) | ||
} | ||
|
||
func logInfo(_ message: @autoclosure () -> String) { | ||
let logMessage = "INFO: \(message())" | ||
print(logMessage) | ||
writeToAppTempFile(content: logMessage) | ||
} | ||
|
||
func logDebug(_ message: @autoclosure () -> String) { | ||
let logMessage = "DEBUG: \(message())" | ||
print(logMessage) | ||
writeToAppTempFile(content: logMessage) | ||
} | ||
|
||
func logFault(_ message: @autoclosure () -> String) { | ||
let logMessage = "FAULT: \(message())" | ||
print(logMessage) | ||
writeToAppTempFile(content: logMessage) | ||
} | ||
|
||
func logError(_ message: @autoclosure () -> String) { | ||
let logMessage = "ERROR: \(message())" | ||
print(logMessage) | ||
writeToAppTempFile(content: logMessage) | ||
} | ||
|
||
func setOutputFileDir(to directory: URL) { | ||
outputDir = directory | ||
} | ||
|
||
func writeToAppTempFile(content: String) -> Void { | ||
DispatchQueue.global(qos: .background).async { | ||
do { | ||
let fileName = "\(self.loggerCreationDateAndTime)-amazon-connect-logs.txt" | ||
let filePath = self.outputDir.appendingPathComponent(fileName) | ||
|
||
if !FileManager.default.fileExists(atPath: filePath.path) { | ||
// Create the file if it doesn't exist | ||
FileManager.default.createFile(atPath: filePath.path, contents: nil, attributes: nil) | ||
} | ||
|
||
// Append content to the file | ||
let fileHandle = try FileHandle(forWritingTo: filePath) | ||
defer { fileHandle.closeFile() } | ||
|
||
// Move to the end of the file before appending | ||
fileHandle.seekToEndOfFile() | ||
let timestamp = Date().description | ||
if let data = "[\(timestamp)] \(content) \n".data(using: .utf8) { | ||
fileHandle.write(data) | ||
} | ||
} catch { | ||
print("ERROR") | ||
} | ||
} | ||
} | ||
} |
8 changes: 2 additions & 6 deletions
8
...hatExamples/iOSChatExample/AmazonConnectChatIOSDemo/Models/NetworkConnectionManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 2 additions & 6 deletions
8
mobileChatExamples/iOSChatExample/AmazonConnectChatIOSDemo/Models/Notifications.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 3 additions & 6 deletions
9
mobileChatExamples/iOSChatExample/AmazonConnectChatIOSDemo/Views/AttachmentButton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters