Enabled log output

This commit is contained in:
2023-11-19 21:32:32 +01:00
parent 559bd03de3
commit 253e9d90ce
4 changed files with 30 additions and 1 deletions

7
Cargo.lock generated
View File

@@ -635,6 +635,12 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "hyper"
version = "0.14.27"
@@ -1289,6 +1295,7 @@ dependencies = [
"async-tftp",
"fern",
"futures",
"humantime",
"libc",
"listenfd",
"log",

View File

@@ -19,4 +19,5 @@ mlua = { version = "0.9.1", features = ["luau-jit", "vendored", "async", "send"]
reqwest = { version = "0.11.22", features = ["stream"] }
listenfd = "1.0.1"
libc = "0.2.150"
users = "0.11.0"
users = "0.11.0"
humantime = "2.1.0"

View File

@@ -6,6 +6,7 @@ use async_tftp::async_trait;
use async_tftp::packet::Error;
use async_tftp::server::handlers::{DirHandler, DirHandlerMode};
use futures::{AsyncRead, AsyncWrite, TryStreamExt};
use log::info;
use reqwest::{Body, StatusCode};
use tokio_util::compat::TokioAsyncWriteCompatExt;
use crate::engine::{Client, Engine, Resource};
@@ -44,6 +45,8 @@ impl async_tftp::server::Handler for Handler {
// .to_str().ok_or(Error::FileNotFound)?.to_owned()
let resource: Resource = self.engine.resolve(path.to_owned(), &mut lua_client, None).await?;
info!("GET {path:?} from {client:?} -> {resource}");
match resource {
Resource::Http(url) => {
// TODO: Add headers describing client
@@ -83,6 +86,7 @@ impl async_tftp::server::Handler for Handler {
for_write: false,
};
let resource: Resource = self.engine.resolve(path.to_owned(), &mut lua_client, size).await?;
info!("PUT {path:?} from {client:?} -> {resource}");
match resource {
Resource::Http(url) => {

View File

@@ -3,6 +3,7 @@ use std::ffi::c_void;
use std::net;
use std::net::{Ipv4Addr, Ipv6Addr};
use std::path::{Path, PathBuf};
use std::time::SystemTime;
use anyhow::anyhow;
use structopt::StructOpt;
use tokio::signal::unix::SignalKind;
@@ -36,6 +37,22 @@ struct Options {
async fn main() -> anyhow::Result<()> {
let opts = Options::from_args();
// Configure logging
fern::Dispatch::new()
.format(|out, message, record| {
out.finish(format_args!(
"[{} {} {}] {}",
humantime::format_rfc3339_seconds(SystemTime::now()),
record.level(),
record.target(),
message
))
})
.level(log::LevelFilter::Debug)
.chain(std::io::stdout())
.chain(fern::log_file("output.log")?)
.apply()?;
let group = opts.group.map(|name| {
if let Ok(gid) = libc::gid_t::from_str_radix(name.as_str(), 10) {
Ok(gid)