Enabled log output
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -635,6 +635,12 @@ version = "1.0.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
|
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "humantime"
|
||||||
|
version = "2.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper"
|
name = "hyper"
|
||||||
version = "0.14.27"
|
version = "0.14.27"
|
||||||
@@ -1289,6 +1295,7 @@ dependencies = [
|
|||||||
"async-tftp",
|
"async-tftp",
|
||||||
"fern",
|
"fern",
|
||||||
"futures",
|
"futures",
|
||||||
|
"humantime",
|
||||||
"libc",
|
"libc",
|
||||||
"listenfd",
|
"listenfd",
|
||||||
"log",
|
"log",
|
||||||
|
|||||||
@@ -19,4 +19,5 @@ mlua = { version = "0.9.1", features = ["luau-jit", "vendored", "async", "send"]
|
|||||||
reqwest = { version = "0.11.22", features = ["stream"] }
|
reqwest = { version = "0.11.22", features = ["stream"] }
|
||||||
listenfd = "1.0.1"
|
listenfd = "1.0.1"
|
||||||
libc = "0.2.150"
|
libc = "0.2.150"
|
||||||
users = "0.11.0"
|
users = "0.11.0"
|
||||||
|
humantime = "2.1.0"
|
||||||
@@ -6,6 +6,7 @@ use async_tftp::async_trait;
|
|||||||
use async_tftp::packet::Error;
|
use async_tftp::packet::Error;
|
||||||
use async_tftp::server::handlers::{DirHandler, DirHandlerMode};
|
use async_tftp::server::handlers::{DirHandler, DirHandlerMode};
|
||||||
use futures::{AsyncRead, AsyncWrite, TryStreamExt};
|
use futures::{AsyncRead, AsyncWrite, TryStreamExt};
|
||||||
|
use log::info;
|
||||||
use reqwest::{Body, StatusCode};
|
use reqwest::{Body, StatusCode};
|
||||||
use tokio_util::compat::TokioAsyncWriteCompatExt;
|
use tokio_util::compat::TokioAsyncWriteCompatExt;
|
||||||
use crate::engine::{Client, Engine, Resource};
|
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()
|
// .to_str().ok_or(Error::FileNotFound)?.to_owned()
|
||||||
let resource: Resource = self.engine.resolve(path.to_owned(), &mut lua_client, None).await?;
|
let resource: Resource = self.engine.resolve(path.to_owned(), &mut lua_client, None).await?;
|
||||||
|
|
||||||
|
info!("GET {path:?} from {client:?} -> {resource}");
|
||||||
|
|
||||||
match resource {
|
match resource {
|
||||||
Resource::Http(url) => {
|
Resource::Http(url) => {
|
||||||
// TODO: Add headers describing client
|
// TODO: Add headers describing client
|
||||||
@@ -83,6 +86,7 @@ impl async_tftp::server::Handler for Handler {
|
|||||||
for_write: false,
|
for_write: false,
|
||||||
};
|
};
|
||||||
let resource: Resource = self.engine.resolve(path.to_owned(), &mut lua_client, size).await?;
|
let resource: Resource = self.engine.resolve(path.to_owned(), &mut lua_client, size).await?;
|
||||||
|
info!("PUT {path:?} from {client:?} -> {resource}");
|
||||||
|
|
||||||
match resource {
|
match resource {
|
||||||
Resource::Http(url) => {
|
Resource::Http(url) => {
|
||||||
|
|||||||
17
src/main.rs
17
src/main.rs
@@ -3,6 +3,7 @@ use std::ffi::c_void;
|
|||||||
use std::net;
|
use std::net;
|
||||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::time::SystemTime;
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use tokio::signal::unix::SignalKind;
|
use tokio::signal::unix::SignalKind;
|
||||||
@@ -36,6 +37,22 @@ struct Options {
|
|||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
let opts = Options::from_args();
|
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| {
|
let group = opts.group.map(|name| {
|
||||||
if let Ok(gid) = libc::gid_t::from_str_radix(name.as_str(), 10) {
|
if let Ok(gid) = libc::gid_t::from_str_radix(name.as_str(), 10) {
|
||||||
Ok(gid)
|
Ok(gid)
|
||||||
|
|||||||
Reference in New Issue
Block a user