Skip to content

Commit e08411a

Browse files
committed
fix(logging): crash on release builds in rotation logger
1 parent 3551df8 commit e08411a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingSession.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,18 @@ final class AWSCloudWatchLoggingSession {
4343
let directory = try directory(for: category, userIdentifier: userIdentifier)
4444
try fileManager.createDirectory(at: directory, withIntermediateDirectories: true)
4545
try (directory as NSURL).setResourceValue(true, forKey: URLResourceKey.isExcludedFromBackupKey)
46-
let cacheMaxSizeInBytes = localStoreMaxSizeInMB * 1048576
46+
47+
// Calculate appropriate file size limit (individual file, not total cache)
48+
// Use a reasonable file size limit that's a fraction of the total cache size
49+
// Ensure it meets the minimum requirement of 1KB
50+
let totalCacheSizeInBytes = localStoreMaxSizeInMB * 1048576
51+
let fileSizeLimitInBytes = max(LogRotation.minimumFileSizeLimitInBytes, totalCacheSizeInBytes / 5)
52+
4753
return try RotatingLogger(directory: directory,
4854
category: category,
4955
namespace: namespace,
5056
logLevel: logLevel,
51-
fileSizeLimitInBytes: cacheMaxSizeInBytes)
57+
fileSizeLimitInBytes: fileSizeLimitInBytes)
5258
}
5359

5460
private static func directory(for category: String, userIdentifier: String?, fileManager: FileManager = .default) throws -> URL {

AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Consumer/CloudWatchLoggingStreamNameFormatter.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,11 @@ struct CloudWatchLoggingStreamNameFormatter {
4444
func formattedStreamName() async -> String {
4545
return "\(await deviceIdentifier ?? "").\(userIdentifier ?? "guest")"
4646
}
47+
48+
// Add the missing deviceIdentifierFromBundle static method
49+
private static func deviceIdentifierFromBundle() -> String? {
50+
// Use bundle identifier as a fallback device identifier
51+
// This provides a consistent identifier per app installation
52+
return Bundle.main.bundleIdentifier
53+
}
4754
}

0 commit comments

Comments
 (0)