Skip to content

fix(logging): crash on release builds in rotation logger #4009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ final class AWSCloudWatchLoggingSession {
let directory = try directory(for: category, userIdentifier: userIdentifier)
try fileManager.createDirectory(at: directory, withIntermediateDirectories: true)
try (directory as NSURL).setResourceValue(true, forKey: URLResourceKey.isExcludedFromBackupKey)
let cacheMaxSizeInBytes = localStoreMaxSizeInMB * 1048576

// Calculate appropriate file size limit (individual file, not total cache)
// Use a reasonable file size limit that's a fraction of the total cache size
// Ensure it meets the minimum requirement of 1KB
let totalCacheSizeInBytes = localStoreMaxSizeInMB * 1048576
let fileSizeLimitInBytes = max(LogRotation.minimumFileSizeLimitInBytes, totalCacheSizeInBytes / 5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why totalCacheSizeInBytes / 5 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the code to better reflect what 5 was.. Its the file count.


return try RotatingLogger(directory: directory,
category: category,
namespace: namespace,
logLevel: logLevel,
fileSizeLimitInBytes: cacheMaxSizeInBytes)
fileSizeLimitInBytes: fileSizeLimitInBytes)
}

private static func directory(for category: String, userIdentifier: String?, fileManager: FileManager = .default) throws -> URL {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ struct CloudWatchLoggingStreamNameFormatter {
func formattedStreamName() async -> String {
return "\(await deviceIdentifier ?? "").\(userIdentifier ?? "guest")"
}

// Add the missing deviceIdentifierFromBundle static method
private static func deviceIdentifierFromBundle() -> String? {
// Use bundle identifier as a fallback device identifier
// This provides a consistent identifier per app installation
return Bundle.main.bundleIdentifier
}
}
Loading