feat: add basic logging
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::{State, commands::CommandSource, scripting};
|
||||
use azalea::prelude::*;
|
||||
use log::info;
|
||||
use mlua::Function;
|
||||
|
||||
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 {
|
||||
Event::Chat(message) => {
|
||||
println!("{}", message.message().to_ansi());
|
||||
info!("{}", message.message().to_ansi());
|
||||
|
||||
let owners = globals.get::<Vec<String>>("OWNERS")?;
|
||||
if message.is_whisper()
|
||||
|
@@ -50,13 +50,8 @@ async fn main() -> ExitCode {
|
||||
eprintln!("failed to set config_path in lua globals: {error:?}");
|
||||
return ExitCode::FAILURE;
|
||||
};
|
||||
|
||||
let Ok(server) = globals.get::<String>("Server") else {
|
||||
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!");
|
||||
if let Err(error) = scripting::logging::init(&lua, &globals) {
|
||||
eprintln!("failed to set up logging wrappers: {error:?}");
|
||||
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 logging;
|
||||
pub mod position;
|
||||
|
Reference in New Issue
Block a user