A lightweight file logger for SwiftUDF applications with encryption support. Designed for fast and simple integration into existing SwiftUDF projects. With just a few lines of code, you can start logging data to a file, either encrypted or unencrypted.
- Supports AES encryption in CBC mode using a native SDK implementation for reliable and efficient performance.
- Supports logging data without encryption.
- Automatic file size management with configurable maximum file size.
- Optimized I/O performance for high-frequency logging
- Supports decrypting data with third-party tools: AAX
- Designed to be simple and easy to use
The library can be added via Swift Package Manager:
.package(url: "https://github.com/urlaunched-com/UDFEncryptedFileLogger", from: "1.0.0")It is recommended to integrate the library in the main application entry point, together with initialization UDF components.
Example showing initialization logger inside a typical SwiftUDF setup:
let encryptedFileURL = applicationSupportDirectory.appending(path: "logger").appendingPathExtension("enc")
store = EnvironmentStore(
initial: AppState(),
loggers: [
.defaultFileLogger(
fileURL: encryptedFileURL,
maxFileSizeInMB: 150,
encryptionMethod: .aesCBC(key: base64SecretKey)
),
]
)You need to provide a private key. The key must be in Base64 format and have a size of 256 bits. You can use the AAX utility to simplify integration with the library.
$ brew install eneko/tap/axxThis CLI tool helps generate a key:
$ axx k > ./.key.pemWith the command below, you can copy the key:
$ cat ./.key.pem | sed -n '2p' | pbcopyIt is recommended to store the key in an .xcconfig file and load it in the main application entry point to configure the logger.
Data can be decrypted at any time using the private key:
axx d -i ./.key.pem logger.encThis will produce logger.enc.plain with the decrypted content.
AES-CBC encrypted data is structured as [IV][Encrypted Data]. This is a common format for storing data encrypted with this method. When the logger exceeds the maximum file size, it removes the oldest logs by deleting the first 20% of the file to ensure space for new content. For a better logging experience, it is recommended to set the maximum file size to 100–200 MB. The logger introduces a delay before writing data to a file and writes data in chunks, allowing I/O operations to be used more efficiently.