cat_loggr/
types.rs

1use std::fmt;
2
3use chrono::{DateTime, Utc};
4
5/// Arguments passed to a [`PostHookCallback`]
6#[derive(Debug)]
7pub struct PostHookCallbackParams {
8	/// The level of the log
9	pub level: String,
10	/// The final formatted text
11	pub text: String,
12	/// The timestamp of execution
13	pub date: DateTime<Utc>,
14	/// The formatted timestamp
15	pub timestamp: String,
16	/// The shard ID
17	pub shard: Option<String>,
18	// context:
19}
20
21/// Arguments passed to a [`PreHookCallback`]
22pub struct PreHookCallbackParams<'a> {
23	/// The level of the log
24	pub level: String,
25	/// The arguments being logged
26	pub args: fmt::Arguments<'a>,
27	/// The timestamp of execution
28	pub date: DateTime<Utc>,
29	/// The formatted timestamp
30	pub timestamp: String,
31	/// The shard ID
32	pub shard: Option<String>,
33}
34
35/// An argument hook callback function
36///
37/// # Arguments
38/// * `args` - The provided argument
39/// * `date` - The timestamp of execution
40pub type ArgHookCallback = fn(args: Option<fmt::Arguments>, date: DateTime<Utc>) -> Option<String>;
41
42/// A post hook callback function
43///
44/// # Arguments
45/// * `params` - The parameters that are sent by the hook
46pub type PostHookCallback = fn(params: PostHookCallbackParams) -> Option<String>;
47
48/// A pre hook callback function
49///
50/// # Arguments
51/// * `params` - The parameters that are sent by the hook
52pub type PreHookCallback = fn(params: PreHookCallbackParams) -> Option<String>;
53
54#[derive(Default)]
55pub struct LogHooks {
56	pub pre: Vec<PreHookCallback>,
57	pub arg: Vec<ArgHookCallback>,
58	pub post: Vec<PostHookCallback>,
59}
60
61impl LogHooks {
62	pub fn new() -> Self {
63		Self {
64			pre: Vec::<PreHookCallback>::new(),
65			arg: Vec::<ArgHookCallback>::new(),
66			post: Vec::<PostHookCallback>::new(),
67		}
68	}
69}