1use async_trait::async_trait;
4
5use rs_genai::prelude::FunctionCall;
6
7use super::{Plugin, PluginResult};
8use crate::context::InvocationContext;
9use crate::events::Event;
10
11pub struct LoggingPlugin;
16
17impl LoggingPlugin {
18 pub fn new() -> Self {
20 Self
21 }
22}
23
24impl Default for LoggingPlugin {
25 fn default() -> Self {
26 Self::new()
27 }
28}
29
30#[async_trait]
31impl Plugin for LoggingPlugin {
32 fn name(&self) -> &str {
33 "logging"
34 }
35
36 async fn before_agent(&self, _ctx: &InvocationContext) -> PluginResult {
37 #[cfg(feature = "tracing-support")]
38 tracing::info!("[plugin:logging] Agent starting");
39 PluginResult::Continue
40 }
41
42 async fn after_agent(&self, _ctx: &InvocationContext) -> PluginResult {
43 #[cfg(feature = "tracing-support")]
44 tracing::info!("[plugin:logging] Agent completed");
45 PluginResult::Continue
46 }
47
48 async fn before_tool(&self, call: &FunctionCall, _ctx: &InvocationContext) -> PluginResult {
49 let _ = call;
50 #[cfg(feature = "tracing-support")]
51 {
52 tracing::info!(tool = %call.name, "[plugin:logging] Tool call starting");
53 tracing::debug!(tool = %call.name, args = %call.args, "[plugin:logging] Tool call args");
54 }
55 PluginResult::Continue
56 }
57
58 async fn after_tool(
59 &self,
60 call: &FunctionCall,
61 _result: &serde_json::Value,
62 _ctx: &InvocationContext,
63 ) -> PluginResult {
64 let _ = call;
65 #[cfg(feature = "tracing-support")]
66 tracing::info!(tool = %call.name, "[plugin:logging] Tool call completed");
67 PluginResult::Continue
68 }
69
70 async fn on_event(&self, event: &Event, _ctx: &InvocationContext) -> PluginResult {
71 let _ = event;
72 #[cfg(feature = "tracing-support")]
73 tracing::debug!(
74 event_id = %event.id,
75 author = %event.author,
76 "[plugin:logging] Event emitted"
77 );
78 PluginResult::Continue
79 }
80}
81
82#[cfg(test)]
83mod tests {
84 use super::*;
85
86 #[test]
87 fn logging_plugin_name() {
88 let p = LoggingPlugin::new();
89 assert_eq!(p.name(), "logging");
90 }
91
92 #[test]
93 fn logging_plugin_default() {
94 let p = LoggingPlugin;
95 assert_eq!(p.name(), "logging");
96 }
97}