diff --git a/.github/workflows/lua.yml b/.github/workflows/lua.yml index a48975f..6310df7 100644 --- a/.github/workflows/lua.yml +++ b/.github/workflows/lua.yml @@ -4,6 +4,7 @@ on: push: branches: - stable + - dev permissions: contents: read diff --git a/src/ffi/lua.rs b/src/ffi/lua.rs index 2f09ac3..ae200ea 100644 --- a/src/ffi/lua.rs +++ b/src/ffi/lua.rs @@ -451,6 +451,15 @@ impl Write for LuaLoggerProducer { // TODO can we make this less verbose? fn logger(_: &Lua, (printer, debug): (LuaValue, Option)) -> LuaResult { let level = if debug.unwrap_or_default() { tracing::Level::DEBUG } else {tracing::Level::INFO }; + let format = tracing_subscriber::fmt::format() + .with_level(true) + .with_target(true) + .with_thread_ids(false) + .with_thread_names(false) + .with_file(false) + .with_line_number(false) + .with_source_location(false); + let success = match printer { LuaValue::Boolean(_) | LuaValue::LightUserData(_) @@ -461,15 +470,6 @@ fn logger(_: &Lua, (printer, debug): (LuaValue, Option)) -> LuaResult return Err(LuaError::BindError), // TODO full BadArgument type?? LuaValue::Nil => { - let format = tracing_subscriber::fmt::format() - .with_level(true) - .with_target(true) - .with_thread_ids(true) - .with_thread_names(true) - .with_ansi(true) - .with_file(false) - .with_line_number(false) - .with_source_location(false); tracing_subscriber::fmt() .event_format(format) .with_max_level(level) @@ -479,37 +479,21 @@ fn logger(_: &Lua, (printer, debug): (LuaValue, Option)) -> LuaResult { let logfile = std::fs::File::create(path.to_string_lossy()).map_err(|e| LuaError::RuntimeError(e.to_string()))?; - let format = tracing_subscriber::fmt::format() - .with_level(true) - .with_target(true) - .with_thread_ids(true) - .with_thread_names(true) - .with_ansi(false) - .with_file(false) - .with_line_number(false) - .with_source_location(false); tracing_subscriber::fmt() .event_format(format) .with_max_level(level) .with_writer(Mutex::new(logfile)) + .with_ansi(false) .try_init() .is_ok() }, LuaValue::Function(cb) => { let (tx, mut rx) = mpsc::unbounded_channel(); - let format = tracing_subscriber::fmt::format() - .with_level(true) - .with_target(true) - .with_thread_ids(false) - .with_thread_names(false) - .with_ansi(false) - .with_file(false) - .with_line_number(false) - .with_source_location(false); let res = tracing_subscriber::fmt() .event_format(format) .with_max_level(level) .with_writer(Mutex::new(LuaLoggerProducer(tx))) + .with_ansi(false) .try_init() .is_ok(); if res {