mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 15:34:53 +01:00
feat: add ability to log to file
This commit is contained in:
parent
e526d874f9
commit
6791055f9e
2 changed files with 17 additions and 1 deletions
|
@ -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"
|
||||
|
|
16
src/lib.rs
16
src/lib.rs
|
@ -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)?)?;
|
||||
|
|
Loading…
Reference in a new issue