Compare commits
1 Commits
32276ba1a3
...
refactor-i
| Author | SHA1 | Date | |
|---|---|---|---|
|
506ce117d3
|
22
Cargo.lock
generated
22
Cargo.lock
generated
@ -2041,6 +2041,16 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
|
||||
[[package]]
|
||||
name = "snitch"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"log",
|
||||
"reqwest",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "snitch_srv"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@ -2050,20 +2060,10 @@ dependencies = [
|
||||
"rocket_db_pools",
|
||||
"rocket_dyn_templates",
|
||||
"serde",
|
||||
"snitchlib",
|
||||
"snitch",
|
||||
"sqlx",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "snitchlib"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"log",
|
||||
"reqwest",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.4.7"
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
[workspace]
|
||||
members = ["snitch", "snitchlib"]
|
||||
members = ["snitch", "snitch_srv"]
|
||||
|
||||
@ -4,14 +4,7 @@ version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
snitchlib = { path = "../snitchlib" }
|
||||
|
||||
anyhow = "*"
|
||||
log = "0.4"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
sqlx = { version = "0.5", features = ["runtime-tokio-rustls", "postgres", "sqlite", "migrate", "macros", "chrono"] }
|
||||
rocket_dyn_templates = { version = "0.1.0-rc.2", features = ["handlebars"] }
|
||||
rocket_db_pools = { version = "0.1.0-rc.2", features = ["sqlx_postgres"] }
|
||||
rocket = { version = "0.5.0-rc.2", features = ["json"] }
|
||||
clap = { version = "4.0.23", features = ["derive", "env"] }
|
||||
reqwest = { version = "0.11.12", default-features = false, features = ["rustls-tls", "serde_json", "blocking", "json"] }
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use log::{Level, LevelFilter, Log, Metadata, Record};
|
||||
use snitchlib::SnitchLogger;
|
||||
use snitch::SnitchLogger;
|
||||
|
||||
struct SimpleLogger;
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use log::{Level, Log, Metadata, Record};
|
||||
use reqwest::blocking;
|
||||
|
||||
@ -22,10 +24,13 @@ impl<L: Log> SnitchLogger<L> {
|
||||
|
||||
impl<L: Log> Log for SnitchLogger<L> {
|
||||
fn enabled(&self, metadata: &Metadata) -> bool {
|
||||
self.wrapped.enabled(metadata) || metadata.level() <= Level::Warn
|
||||
dbg!(self.wrapped.enabled(metadata) || metadata.level() <= Level::Warn)
|
||||
}
|
||||
|
||||
fn log(&self, record: &Record) {
|
||||
eprintln!("log called");
|
||||
eprintln!("log called");
|
||||
eprintln!("log called");
|
||||
eprintln!("log called");
|
||||
self.wrapped.log(record);
|
||||
|
||||
@ -43,7 +48,12 @@ impl<L: Log> Log for SnitchLogger<L> {
|
||||
};
|
||||
|
||||
let client = blocking::Client::new();
|
||||
if let Err(e) = client.post(&self.url).json(&record).send() {
|
||||
if let Err(e) = client
|
||||
.post(&self.url)
|
||||
.json(&record)
|
||||
.timeout(Duration::from_secs(2))
|
||||
.send()
|
||||
{
|
||||
// TODO: log error (without sending it)
|
||||
eprintln!("failed to send log record: {e:?}");
|
||||
}
|
||||
17
snitch_srv/Cargo.toml
Normal file
17
snitch_srv/Cargo.toml
Normal file
@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "snitch_srv"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
snitch = { path = "../snitch" }
|
||||
|
||||
anyhow = "*"
|
||||
log = "0.4"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
sqlx = { version = "0.5", features = ["runtime-tokio-rustls", "postgres", "sqlite", "migrate", "macros", "chrono"] }
|
||||
rocket_dyn_templates = { version = "0.1.0-rc.2", features = ["handlebars"] }
|
||||
rocket_db_pools = { version = "0.1.0-rc.2", features = ["sqlx_postgres"] }
|
||||
rocket = { version = "0.5.0-rc.2", features = ["json"] }
|
||||
clap = { version = "4.0.23", features = ["derive", "env"] }
|
||||
@ -1,5 +1,5 @@
|
||||
use rocket::{http::Status, serde::json::Json, State};
|
||||
use snitchlib::LogMsg;
|
||||
use snitch::LogMsg;
|
||||
use sqlx::query;
|
||||
|
||||
use crate::database::Database;
|
||||
@ -1,10 +0,0 @@
|
||||
[package]
|
||||
name = "snitchlib"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
reqwest = { version = "0.11.12", default-features = false, features = ["rustls-tls", "serde_json", "blocking", "json"] }
|
||||
Reference in New Issue
Block a user