-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
9 changed files
with
262 additions
and
16 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
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,12 @@ | ||
// This file is automatically generated, so please do not edit it. | ||
// Generated by `flutter_rust_bridge`@ 2.3.0. | ||
|
||
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import | ||
|
||
import '../frb_generated.dart'; | ||
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; | ||
|
||
// These types are ignored because they are not used by any `pub` functions: `LogWriter` | ||
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`, `flush`, `make_writer_for`, `make_writer`, `write` | ||
|
||
Stream<Uint8List> initLog() => RustLib.instance.api.crateApiLogInitLog(); |
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
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
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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod daemon; | ||
pub mod log; |
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,48 @@ | ||
use crate::frb_generated::StreamSink; | ||
use std::sync::Arc; | ||
use tracing::{info, level_filters::LevelFilter}; | ||
use tracing_subscriber::{fmt::MakeWriter, layer::SubscriberExt, util::SubscriberInitExt, Layer}; | ||
|
||
#[derive(Clone)] | ||
struct LogWriter { | ||
sink: Arc<StreamSink<Vec<u8>>>, | ||
} | ||
|
||
impl std::io::Write for LogWriter { | ||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { | ||
self.sink.add(buf.into()).unwrap(); | ||
Ok(buf.len()) | ||
} | ||
|
||
fn flush(&mut self) -> std::io::Result<()> { | ||
// Nothing to do here | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl<'a> MakeWriter<'a> for LogWriter { | ||
type Writer = Self; | ||
|
||
fn make_writer(&'a self) -> Self::Writer { | ||
self.clone() | ||
} | ||
|
||
fn make_writer_for(&'a self, _meta: &tracing::Metadata<'_>) -> Self::Writer { | ||
self.clone() | ||
} | ||
} | ||
|
||
pub fn init_log(log_sink: StreamSink<Vec<u8>>) { | ||
let make_writer = LogWriter { | ||
sink: Arc::new(log_sink), | ||
}; | ||
|
||
let stdout_log = tracing_subscriber::fmt::layer() | ||
.pretty() | ||
.with_writer(make_writer); | ||
tracing_subscriber::registry() | ||
.with(stdout_log.with_filter(LevelFilter::DEBUG)) | ||
.init(); | ||
|
||
info!("logging initialized..."); | ||
} |
Oops, something went wrong.