1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright (c) 2026 Kirky.X
// SPDX-License-Identifier: MIT
//! Audit logging implementation
//!
//! This module provides audit logging with DoS protection and async processing.
use crateSharedCache;
use crateAuditLog;
use Future;
use Pin;
use Arc;
// HIGH 修复(#298):sanitize_error_message 现为无条件 pub(crate)——
// ApiError::internal_* 构造器据此强制脱敏,不再依赖调用方自觉。
pub use sanitize_error_message;
pub use ;
// =============================================================================
// AuditSink trait — abstract audit log storage backend
// =============================================================================
/// Abstract audit log storage backend.
///
/// `AuditSink` decouples *where* audit logs are stored from the
/// `AppAuditLogger`'s DoS-protection machinery (semaphore, queue,
/// merge-lock). The default implementation is an in-memory ring buffer
/// (`AppAuditLogger`'s existing `SharedCache`-backed storage). When the
/// `inklog` feature is enabled, an [`InklogAuditSink`] bridges audit
/// events to inklog's structured output pipeline.
///
/// Uses `Pin<Box<dyn Future>>` instead of `async-trait` to avoid pulling
/// in an extra dependency — mirrors the `RateLimiter` trait pattern.
// inklog bridge — available when both `security` and `inklog` features are on.
pub use InklogAuditSink;
/// Batch of audit logs for async processing.
///
/// Internal struct used to pass user ID and log entry through the async channel.
pub
/// Audit logger with DoS protection
///
/// Security features:
/// - Semaphore-based rate limiting to prevent log flooding
/// - Per-user log count limits
/// - Async processing to avoid blocking main threads
/// - Fallback storage when async channel is full (prevents log loss)
///
/// Builder for creating AppAuditLogger with custom configuration.
///
/// This builder allows fine-grained control over audit logger settings
/// including log limits, concurrency, and queue size.
///
/// # Examples
///
/// ```ignore
/// use sdforge::security::AppAuditLogger;
///
/// #[tokio::main]
/// async fn main() {
/// let logger = AppAuditLogger::builder()
/// .max_logs_per_user(500)
/// .max_concurrent_ops(50)
/// .queue_size(2000)
/// .build();
/// let _ = logger;
/// }
/// ```