Skip to content

Commit

Permalink
Adjust log
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft committed Nov 23, 2022
1 parent 7774aaa commit 05368ea
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 22 deletions.
4 changes: 2 additions & 2 deletions bins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ release-cross: dist

.PHONY: run run-gui run-latex
run:
RUST_LOG=info cargo run --package ayaka-check -- $(FILE) --auto
cargo run --package ayaka-check -- $(FILE) --auto
run-gui:
cd ayaka-gui && $(MAKE) run FILE=$(FILE)
run-latex:
RUST_LOG=info cargo run --package ayaka-latex -- $(FILE) -o $(basename $(FILE)).tex
cargo run --package ayaka-latex -- $(FILE) -o $(basename $(FILE)).tex
2 changes: 1 addition & 1 deletion bins/ayaka-check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"
ayaka-runtime = { path = "../../utils/ayaka-runtime" }
tokio = { version = "1", features = ["macros", "rt"] }
clap = { version = "4.0", features = ["derive"] }
env_logger = "0.9"
flexi_logger = { version = "0.24", default-features = false, features = ["colors"] }
12 changes: 8 additions & 4 deletions bins/ayaka-check/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ayaka_runtime::{anyhow::Result, log::LevelFilter, *};
use ayaka_runtime::{anyhow::Result, *};
use clap::Parser;
use flexi_logger::{LogSpecification, Logger};
use std::{
ffi::OsString,
io::{stdin, stdout, Write},
Expand Down Expand Up @@ -34,9 +35,12 @@ fn pause(auto: bool) -> Result<()> {
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
let opts = Options::parse();
env_logger::Builder::from_default_env()
.filter_module("wasmer", LevelFilter::Warn)
.try_init()?;
let spec = LogSpecification::parse("warn,ayaka=debug")?;
let _log_handle = Logger::with(spec)
.log_to_stdout()
.set_palette("b1;3;2;4;6".to_string())
.use_utc()
.start()?;
let context = Context::open(&opts.input, FrontendType::Text);
pin_mut!(context);
while let Some(status) = context.next().await {
Expand Down
15 changes: 7 additions & 8 deletions bins/ayaka-gui/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,15 @@ fn main() -> Result<()> {
.plugin(tauri_plugin_localhost::Builder::new(port).build())
.setup(|app| {
let ident = app.config().tauri.bundle.identifier.clone();
let spec = LogSpecification::parse("warn,ayaka=debug")?;
let log_handle = if cfg!(debug_assertions) {
Logger::with(LogSpecification::parse(
"debug,wasmer=warn,wasmtime=warn,wasi=info,regalloc=info,cranelift=info",
)?)
.log_to_stdout()
.set_palette("b1;3;2;4;6".to_string())
.use_utc()
.start()?
Logger::with(spec)
.log_to_stdout()
.set_palette("b1;3;2;4;6".to_string())
.use_utc()
.start()?
} else {
Logger::with(LogSpecification::parse("info,wasmer=warn,wasmtime=warn")?)
Logger::with(spec)
.log_to_file(
FileSpec::default()
.directory(app.path_resolver().app_log_dir().unwrap())
Expand Down
2 changes: 1 addition & 1 deletion bins/ayaka-gui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
clearScreen: false,
envPrefix: ['VITE_', 'TAURI_', 'RUST_'],
envPrefix: ['VITE_', 'TAURI_'],
build: {
target: ['es2021', 'chrome97', 'safari13'],
minify: !env.TAURI_DEBUG ? 'esbuild' : false,
Expand Down
2 changes: 1 addition & 1 deletion bins/ayaka-latex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"
ayaka-runtime = { path = "../../utils/ayaka-runtime" }
tokio = { version = "1", features = ["fs", "io-util", "macros", "rt"] }
clap = { version = "4.0", features = ["derive"] }
env_logger = "0.9"
flexi_logger = { version = "0.24", default-features = false, features = ["colors"] }
12 changes: 8 additions & 4 deletions bins/ayaka-latex/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
mod writer;

use ayaka_runtime::{anyhow::Result, log::LevelFilter, *};
use ayaka_runtime::{anyhow::Result, *};
use clap::Parser;
use flexi_logger::{LogSpecification, Logger};
use std::ffi::OsString;
use writer::LaTeXWriter;

Expand All @@ -18,9 +19,12 @@ pub struct Options {
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
let opts = Options::parse();
env_logger::Builder::from_default_env()
.filter_module("wasmer", LevelFilter::Warn)
.try_init()?;
let spec = LogSpecification::parse("warn")?;
let _log_handle = Logger::with(spec)
.log_to_stdout()
.set_palette("b1;3;2;4;6".to_string())
.use_utc()
.start()?;
let context = Context::open(&opts.input, FrontendType::Latex);
let mut ctx = context.await?;

Expand Down
7 changes: 6 additions & 1 deletion utils/ayaka-runtime/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,17 @@ impl<M: RawModule> Runtime<M> {
fn new_linker(root_path: impl AsRef<Path>) -> Result<M::Linker> {
let mut store = M::Linker::new(root_path)?;
let log_func = store.wrap_with_args(|data: Record| {
let module_path = format!(
"{}::<plugin>::{}",
module_path!(),
data.module_path.unwrap_or_default()
);
log::logger().log(
&log::Record::builder()
.level(data.level)
.target(&data.target)
.args(format_args!("{}", data.msg))
.module_path(data.module_path.as_deref())
.module_path(Some(&module_path))
.file(data.file.as_deref())
.line(data.line)
.build(),
Expand Down

0 comments on commit 05368ea

Please sign in to comment.