mirror of
https://github.com/sadoyan/aralez.git
synced 2026-10-23 14:11:35 +08:00
added inventory for immutable core logging files
This commit is contained in:
Generated
+10
@@ -146,6 +146,7 @@ dependencies = [
|
|||||||
"hyper",
|
"hyper",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
"instant-acme",
|
"instant-acme",
|
||||||
|
"inventory",
|
||||||
"jsonwebtoken",
|
"jsonwebtoken",
|
||||||
"k8s-openapi",
|
"k8s-openapi",
|
||||||
"kube",
|
"kube",
|
||||||
@@ -1799,6 +1800,15 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "inventory"
|
||||||
|
version = "0.3.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4f0c30c76f2f4ccee3fe55a2435f691ca00c0e4bd87abe4f4a851b1d4dac39b"
|
||||||
|
dependencies = [
|
||||||
|
"rustversion",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "is_terminal_polyfill"
|
name = "is_terminal_polyfill"
|
||||||
version = "1.70.2"
|
version = "1.70.2"
|
||||||
|
|||||||
@@ -65,3 +65,4 @@ k8s-openapi = { version = "0.28.0", features = ["v1_32"] }
|
|||||||
futures = "0.3.34"
|
futures = "0.3.34"
|
||||||
lazy_static = "1.5.0"
|
lazy_static = "1.5.0"
|
||||||
anyhow = "1.0.103"
|
anyhow = "1.0.103"
|
||||||
|
inventory = "0.3.24"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::logging::core::StructuredSystemLog;
|
use crate::logging::core::StructuredSystemLog;
|
||||||
use crate::logging::types::WriteLog;
|
use crate::logging::types::{LogBackendPlugin, WriteLog};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
@@ -28,7 +28,15 @@ pub struct ElasticSearch;
|
|||||||
impl WriteLog for ElasticSearch {
|
impl WriteLog for ElasticSearch {
|
||||||
fn writelog(&self, msg: &StructuredSystemLog) {
|
fn writelog(&self, msg: &StructuredSystemLog) {
|
||||||
if let Ok(jsonmsg) = serde_json::to_string(&msg) {
|
if let Ok(jsonmsg) = serde_json::to_string(&msg) {
|
||||||
println!("Connecting to {} - {}:{} => {}", ELASTIC.hosts, ELASTIC.user, ELASTIC.password, jsonmsg);
|
// ElasticSearch logic is not yet implemented.
|
||||||
|
println!("{} - {}:{} => {}", ELASTIC.hosts, ELASTIC.user, ELASTIC.password, jsonmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inventory::submit! {
|
||||||
|
LogBackendPlugin {
|
||||||
|
name: "elasticsearch",
|
||||||
|
factory: || Box::new(ElasticSearch),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
use crate::logging::core::StructuredSystemLog;
|
||||||
|
use crate::logging::types::{LogBackendPlugin, WriteLog};
|
||||||
|
|
||||||
|
pub struct Example;
|
||||||
|
|
||||||
|
impl WriteLog for Example {
|
||||||
|
fn writelog(&self, msg: &StructuredSystemLog) {
|
||||||
|
// Here comes the backend logic
|
||||||
|
println!("Sending log Example : {:?}", msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mandatory with name: matching value of "log_structired" in main.yaml
|
||||||
|
inventory::submit! {
|
||||||
|
LogBackendPlugin {
|
||||||
|
name: "example",
|
||||||
|
factory: || Box::new(Example),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
pub mod core;
|
pub mod core;
|
||||||
pub mod elasticsearch;
|
pub mod elasticsearch;
|
||||||
|
pub mod example;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|||||||
+23
-6
@@ -1,13 +1,30 @@
|
|||||||
use crate::logging::core::StructuredSystemLog;
|
use crate::logging::core::StructuredSystemLog;
|
||||||
use crate::logging::elasticsearch::ElasticSearch;
|
use std::collections::HashMap;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
pub trait WriteLog {
|
pub trait WriteLog: Send + Sync {
|
||||||
fn writelog(&self, msg: &StructuredSystemLog);
|
fn writelog(&self, msg: &StructuredSystemLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct LogBackendPlugin {
|
||||||
|
pub name: &'static str,
|
||||||
|
pub factory: fn() -> Box<dyn WriteLog>,
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory::collect!(LogBackendPlugin);
|
||||||
|
|
||||||
|
static BACKENDS: LazyLock<HashMap<&'static str, Box<dyn WriteLog>>> = LazyLock::new(|| {
|
||||||
|
let mut map = HashMap::new();
|
||||||
|
for plugin in inventory::iter::<LogBackendPlugin> {
|
||||||
|
map.insert(plugin.name, (plugin.factory)());
|
||||||
|
}
|
||||||
|
map
|
||||||
|
});
|
||||||
|
|
||||||
pub fn sendlog(backend: &str, msg: &StructuredSystemLog) {
|
pub fn sendlog(backend: &str, msg: &StructuredSystemLog) {
|
||||||
match backend {
|
if let Some(logger) = BACKENDS.get(backend) {
|
||||||
"elasticsearch" => ElasticSearch.writelog(msg),
|
logger.writelog(msg);
|
||||||
"somewhereelse" => println!("somewhereelse"),
|
} else {
|
||||||
_ => log::warn!("Unsupported logging mechanism : {}", backend),
|
log::warn!("Unsupported logging mechanism: {}", backend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user