-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fca24d5
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[build] | ||
target = "wasm32-wasi" | ||
|
||
[target.wasm32-wasi] | ||
runner = "lunatic" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
/Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "logger-rs" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
A logging library for lunatic Rust applications. | ||
|
||
## Problem | ||
|
||
Current logging solutions in Rust (log, tracing, ...) depend on global static variables that are | ||
initialized at the start of the app. E.g. | ||
|
||
```rust | ||
// tracing | ||
tracing::subscriber::set_global_default(subscriber) | ||
.expect("setting default subscriber failed"); | ||
// env_logger | ||
Builder::new() | ||
.parse(&env::var("MY_APP_LOG").unwrap_or_default()) | ||
.init(); | ||
// ... | ||
``` | ||
|
||
This doesn't work in lunatic, where each process gets their own memory space. You would need to | ||
re-initialize the logger for each process, and that is not practical. | ||
|
||
## Solution | ||
|
||
Have a "logger" process registered under a well-defined (e.g. lunatic::logger`) name and for every: | ||
|
||
```rust | ||
log::info!("informational message"); | ||
log::warn!("warning message"); | ||
log::error!("this is an error {}", "message"); | ||
``` | ||
|
||
look up the name and send a message to it. | ||
|
||
## Implementation suggestions | ||
|
||
### 1. Swapable subscriber | ||
|
||
The well known process should just define a message interface. This means that we can provide a | ||
simple implementation that writes to standard out: | ||
|
||
```rust | ||
logger:init(); | ||
``` | ||
|
||
But the community could also provide their own implementations too: | ||
|
||
```rust | ||
open_telemetry_logger:init(); | ||
``` | ||
|
||
### 2. Tracing | ||
|
||
We could support in-process tracing similar to: https://crates.io/crates/tracing. Depending on the | ||
lifetime of the span. | ||
|
||
### 3. Supervision | ||
|
||
The subscriber should be an `AbstractProcess` so that it can be plugged into a supervisor? | ||
|
||
### 4. Lookup optimization | ||
|
||
Having one subscriber for all processes could become a bottleneck. Looking it up could consist of | ||
two parts: | ||
|
||
1. Look up a well-known name (e.g. `lunatic::logger`) | ||
2. Ask it for a subscriber | ||
|
||
That way the well known process could maintain a pool of subscribers that is handed out to others. | ||
|
||
Once it's looked up, we could save the subscriber process in a process local variable so that we | ||
don't need to look it up each time we do: | ||
```rust | ||
log::info!("informational message"); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn it_works() { | ||
let result = 2 + 2; | ||
assert_eq!(result, 4); | ||
} | ||
} |