Skip to content

Commit 0e7d11e

Browse files
committed
worked on review comment
1 parent e08411a commit 0e7d11e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingSession.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ final class AWSCloudWatchLoggingSession {
4848
// Use a reasonable file size limit that's a fraction of the total cache size
4949
// Ensure it meets the minimum requirement of 1KB
5050
let totalCacheSizeInBytes = localStoreMaxSizeInMB * 1048576
51-
let fileSizeLimitInBytes = max(LogRotation.minimumFileSizeLimitInBytes, totalCacheSizeInBytes / 5)
52-
51+
let fileSizeLimitInBytes = max(
52+
LogRotation.minimumFileSizeLimitInBytes,
53+
totalCacheSizeInBytes / LogRotation.fileCountLimit
54+
)
55+
5356
return try RotatingLogger(directory: directory,
5457
category: category,
5558
namespace: namespace,

AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogRotation.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ final class LogRotation {
1717
}
1818

1919
static let minimumFileSizeLimitInBytes = 1024 /* 1KB */
20+
static let fileCountLimit: Int = 5
2021

2122
/// The name pattern of files managed by `LogRotation`.
2223
private static let filePattern = #"amplify[.]([0-9])[.]log"#
2324

2425
let directory: URL
25-
let fileCountLimit: Int = 5
26+
2627
let fileSizeLimitInBytes: UInt64
2728

2829
private(set) var currentLogFile: LogFile {
@@ -40,7 +41,7 @@ final class LogRotation {
4041
self.directory = directory.absoluteURL
4142
self.fileSizeLimitInBytes = UInt64(fileSizeLimitInBytes)
4243
self.currentLogFile = try Self.selectNextLogFile(from: self.directory,
43-
fileCountLimit: fileCountLimit,
44+
fileCountLimit: Self.fileCountLimit,
4445
fileSizeLimitInBytes: self.fileSizeLimitInBytes)
4546
}
4647

@@ -55,7 +56,7 @@ final class LogRotation {
5556
/// 3. If no files matching #1 are present, the file with the oldest last modified date is cleared and selected.
5657
func rotate() throws {
5758
self.currentLogFile = try Self.selectNextLogFile(from: self.directory,
58-
fileCountLimit: self.fileCountLimit,
59+
fileCountLimit: Self.fileCountLimit,
5960
fileSizeLimitInBytes: self.fileSizeLimitInBytes)
6061
}
6162

0 commit comments

Comments
 (0)