feat: add ability to log to file

This commit is contained in:
əlemi 2023-09-05 23:57:57 +02:00
parent e526d874f9
commit 6791055f9e
2 changed files with 17 additions and 1 deletions

View file

@ -11,3 +11,5 @@ codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/cod
mlua = { version = "0.9.0", features = ["module", "luajit"] }
thiserror = "1.0.47"
derive_more = "0.99.17"
tracing-subscriber = "0.3.17"
tracing = "0.1.37"

View file

@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{sync::{Arc, Mutex}, fs::File};
use codemp::prelude::*;
use mlua::prelude::*;
@ -179,9 +179,23 @@ impl LuaUserData for LuaRowCol {
// setup library logging to file
fn setup_tracing(_: &Lua, (path,): (String,)) -> LuaResult<()> {
let log_file = File::create(path)?;
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.with_writer(Mutex::new(log_file))
.init();
Ok(())
}
// define module and exports
#[mlua::lua_module]
fn libcodemp_nvim(lua: &Lua) -> LuaResult<LuaTable> {
let exports = lua.create_table()?;
exports.set("setup_tracing", lua.create_function(setup_tracing)?)?;
exports.set("connect", lua.create_function(connect)?)?;
exports.set("join", lua.create_function(join)?)?;
exports.set("create", lua.create_function(create)?)?;