# Pinenut Log
[中文文档](./README-CN.md) ・ [English](./README.md)
An extremely high performance logging system for clients (iOS, Android, Desktop), written in Rust.
[![codecov](https://codecov.io/gh/TangentW/Pinenut/graph/badge.svg)](https://codecov.io/gh/TangentW/Pinenut)
[![Crates.io](https://img.shields.io/crates/v/pinenut-log)](https://crates.io/crates/pinenut-log)
[![Cocoapods Version](https://img.shields.io/cocoapods/v/Pinenut)](https://cocoapods.org/pods/Pinenut)
## Overview
![Architecture](assets/architecture.svg)
### Compression
Pinenut supports streaming log compression, it uses the `Zstandard (aka zstd)`, a high performance compression algorithm that has a good balance between compression rate and speed.
### Encryption
Pinenut uses the `AES 128` algorithm for symmetric encryption during logging. To prevent embedding the symmetric key directly into the code, Pinenut uses `ECDH` for key negotiation (RSA is not used because its key are too long). When initializing the Logger, there is no need to provide the symmetric encryption key, instead the ECDH public key should be passed.
Pinenut uses `secp256r1` elliptic curve for ECDH. You can generate the secret and public keys for encryption yourself, or use Pinenut's built-in command line tool: `pinenut-cli`.
### Buffering
In order to minimize IO frequency, Pinenut buffers the log data before writing to the file. Client programs may exit unexpectedly (e.g., crash), Pinenut uses `mmap` as buffer support, so that if the program unexpectedly exits, the OS can still help to persist the buffered data. The next time the Logger is initialized, the buffered data is automatically read and written back to the log file.
In addition, Pinenut implements a `double-buffering` system to improve buffer read/write performance and prevent asynchronous IOs from affecting logging of the current thread.
### Extraction
With Pinenut, we don't need to retrieve all the log files in the directory to extract logs, it provides convenient extraction capabilities and supports extraction in time ranges with minute granularity.
### Parsing
The content of Pinenut log files is a special binary sequence after encoding, compression and encryption, and we can parse the log files using the parsing capabilities provided by Pinenut.
## Installation
Pinenut provides APIs for these languages: `Swift`, `Rust`. `Kotlin` will be supported in the future.
### Swift Package Manager
```swift
.package(url: "https://github.com/TangentW/Pinenut.git", from: "0.0.1")
```
### CocoaPods
```ruby
pod 'Pinenut'
```
### Rust Cargo
```toml
[dependencies]
pinenut-log = 0.0.1
```
## Usage
Pinenut's APIs are generally similar regardless of the language used.
### Logger Initialization
Pinenut uses a `Logger` instance for logging. Before we initialize the Logger, we need to pass in the logger identifier and the path to the directory where the log files are stored to construct the `Domain` structure.
We can customize the Logger by explicitly specifying `Config`, see the API documentation for details.