Skip to main content

rex_logger/memory_logger/
config.rs

1//! Configuration types and constants for the memory-based script logging system.
2//!
3//! This module provides the core data structures and configuration constants used
4//! by the script logging functionality. The memory logger captures log entries
5//! from Rhai scripts during execution and stores them in memory for later retrieval.
6use chrono::{DateTime, Utc};
7
8/// Target identifier for logging events to both Runner output and syslogs.
9pub const RUNNER_AND_SYSLOG_TARGET: &str = "runner_and_syslog_target";
10
11/// Target identifier for logging events to only Runner output.
12pub const RUNNER_TARGET: &str = "runner_target";
13
14/// Target identifier for logging events to only Runner output that comes from script logs.
15pub const RUNNER_TARGET_FOR_SCRIPT_LOGS: &str = "runner_target_for_script_logs";
16
17/// Default message length limit when not configured is 2Kb
18pub const DEFAULT_MESSAGE_LENGTH_LIMIT: usize = 2048;
19
20/// Maximum number of log entries that can be stored in memory
21pub const DEFAULT_LOG_ENTRIES_LIMIT: usize = 1000;
22
23/// Represents a single log entry captured from script execution.
24///
25/// This structure contains all the essential information about a log event
26/// that occurred during Rhai script execution.
27///
28/// # Fields
29///
30/// * `timestamp` - UTC timestamp when the log entry was created
31/// * `line_number` - Line number in the script where the log occurred
32/// * `message` - The actual log message content
33#[derive(Debug, Clone)]
34pub struct LogEntry {
35    pub timestamp: DateTime<Utc>,
36    pub line_number: u32,
37    pub level: String,
38    pub message: String,
39    pub rhai_api_name: Option<String>,
40}
41
42/// Represents the execution context of a Rhai script function.
43///
44/// # Fields
45///
46/// * `function_name` - The name of the Rhai function currently being executed
47/// * `line_number` - The line number in the script where execution is occurring
48#[derive(Debug, Clone)]
49pub struct RhaiContext {
50    pub rhai_api_name: Option<String>,
51    pub line_number: u32,
52}