feat: add basic logging
This commit is contained in:
parent
4fa508ec81
commit
a937db0be6
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1180,6 +1180,7 @@ dependencies = [
|
|||||||
"azalea",
|
"azalea",
|
||||||
"clap",
|
"clap",
|
||||||
"futures",
|
"futures",
|
||||||
|
"log",
|
||||||
"mlua",
|
"mlua",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
@ -20,6 +20,7 @@ anyhow = "1"
|
|||||||
azalea = { git = "https://github.com/azalea-rs/azalea.git" }
|
azalea = { git = "https://github.com/azalea-rs/azalea.git" }
|
||||||
clap = { version = "4", features = ["derive"] }
|
clap = { version = "4", features = ["derive"] }
|
||||||
futures = "0"
|
futures = "0"
|
||||||
|
log = { version = "0" }
|
||||||
mlua = { version = "0", features = ["async", "luau", "send"] }
|
mlua = { version = "0", features = ["async", "luau", "send"] }
|
||||||
parking_lot = { version = "0" }
|
parking_lot = { version = "0" }
|
||||||
tokio = { version = "1", features = ["macros"] }
|
tokio = { version = "1", features = ["macros"] }
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::{State, commands::CommandSource, scripting};
|
use crate::{State, commands::CommandSource, scripting};
|
||||||
use azalea::prelude::*;
|
use azalea::prelude::*;
|
||||||
|
use log::info;
|
||||||
use mlua::Function;
|
use mlua::Function;
|
||||||
|
|
||||||
pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow::Result<()> {
|
pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow::Result<()> {
|
||||||
@ -7,7 +8,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> anyhow:
|
|||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::Chat(message) => {
|
Event::Chat(message) => {
|
||||||
println!("{}", message.message().to_ansi());
|
info!("{}", message.message().to_ansi());
|
||||||
|
|
||||||
let owners = globals.get::<Vec<String>>("OWNERS")?;
|
let owners = globals.get::<Vec<String>>("OWNERS")?;
|
||||||
if message.is_whisper()
|
if message.is_whisper()
|
||||||
|
@ -50,13 +50,8 @@ async fn main() -> ExitCode {
|
|||||||
eprintln!("failed to set config_path in lua globals: {error:?}");
|
eprintln!("failed to set config_path in lua globals: {error:?}");
|
||||||
return ExitCode::FAILURE;
|
return ExitCode::FAILURE;
|
||||||
};
|
};
|
||||||
|
if let Err(error) = scripting::logging::init(&lua, &globals) {
|
||||||
let Ok(server) = globals.get::<String>("Server") else {
|
eprintln!("failed to set up logging wrappers: {error:?}");
|
||||||
eprintln!("no server defined in lua globals!");
|
|
||||||
return ExitCode::FAILURE;
|
|
||||||
};
|
|
||||||
let Ok(username) = globals.get::<String>("Username") else {
|
|
||||||
eprintln!("no username defined in lua globals!");
|
|
||||||
return ExitCode::FAILURE;
|
return ExitCode::FAILURE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
41
src/scripting/logging.rs
Normal file
41
src/scripting/logging.rs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
use log::{debug, error, info, trace, warn};
|
||||||
|
use mlua::{Lua, Result, Table};
|
||||||
|
|
||||||
|
pub fn init(lua: &Lua, globals: &Table) -> Result<()> {
|
||||||
|
globals.set(
|
||||||
|
"error",
|
||||||
|
lua.create_function(|_, message: String| {
|
||||||
|
error!("{message}");
|
||||||
|
Ok(())
|
||||||
|
})?,
|
||||||
|
)?;
|
||||||
|
globals.set(
|
||||||
|
"warn",
|
||||||
|
lua.create_function(|_, message: String| {
|
||||||
|
warn!("{message}");
|
||||||
|
Ok(())
|
||||||
|
})?,
|
||||||
|
)?;
|
||||||
|
globals.set(
|
||||||
|
"info",
|
||||||
|
lua.create_function(|_, message: String| {
|
||||||
|
info!("{message}");
|
||||||
|
Ok(())
|
||||||
|
})?,
|
||||||
|
)?;
|
||||||
|
globals.set(
|
||||||
|
"debug",
|
||||||
|
lua.create_function(|_, message: String| {
|
||||||
|
debug!("{message}");
|
||||||
|
Ok(())
|
||||||
|
})?,
|
||||||
|
)?;
|
||||||
|
globals.set(
|
||||||
|
"trace",
|
||||||
|
lua.create_function(|_, message: String| {
|
||||||
|
trace!("{message}");
|
||||||
|
Ok(())
|
||||||
|
})?,
|
||||||
|
)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
@ -1,2 +1,3 @@
|
|||||||
pub mod client;
|
pub mod client;
|
||||||
|
pub mod logging;
|
||||||
pub mod position;
|
pub mod position;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user