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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//! Tracing-based logging surface for `crypt_guard`.
//!
//! # Responsibility scope
//! This module owns the `init_log` helper function that initializes a
//! `tracing_subscriber` once in the binary entry point, and the legacy
//! `initialize_logger` shim that the `activate_log` proc-macro attribute emits.
//!
//! The old `Lazy<Mutex<Log>>` global, `Log` struct, `write_log_file`, and
//! `append_log` string-buffer machinery have been removed. All diagnostic output
//! now flows through `tracing` structured events to whatever subscriber is installed.
//!
//! # API surface preserved for backward compatibility
//! The module still exports `LOGGER` (now a no-op unit value) and `initialize_logger`
//! so that existing call sites compiled against the old API continue to compile.
//! They emit a tracing `info!` event instead of writing to a string buffer.
//!
//! # Key types exported
//! - `initialize_logger` — one-shot tracing subscriber init (called by `activate_log!` expansion)
//! - `init_log` — ergonomic `tracing::Level`-typed initializer for binary entry points
//! - `LOGGER` — compatibility shim (zero-state; does nothing)
//!
//! # Concurrency
//! No global mutable state. Tracing uses lock-free internal queues.
//!
//! # Errors
//! `init_log` is infallible; it ignores the error from `try_init` when a subscriber
//! is already registered (e.g. in tests that call init multiple times).
//!
//! # Examples
//! ```rust,no_run
//! use crypt_guard::log::init_log;
//! init_log(tracing::Level::INFO);
//! tracing::info!(phase = "startup", "crypt_guard initialized");
//! ```
use PathBuf;
use Level;
use *;
use ;
// ── Compatibility shim ────────────────────────────────────────────────────────
/// Legacy compatibility stub.
///
/// # Description
/// Previously a `Lazy<Mutex<Log>>`; now a zero-size unit type. Retained so that code
/// that imports `crypt_guard::log::LOGGER` or references it in `log_activity!` macro
/// expansions still compiles. No locking, no string buffer, no I/O.
///
/// Any code that previously called `LOGGER.lock()…append_log(…)` should migrate to
/// using `tracing::info!(…)` directly, or let the `log_activity!` macro handle it.
;
/// Global logger compatibility shim — zero state, never locks.
///
/// # Description
/// Replaces the old `Lazy<Mutex<Log>>`. Retained for source compatibility only.
pub static LOGGER: LoggerCompat = LoggerCompat;
// ── Initializer ────────────────────────────────────────────────────────────────
/// Initialize the `tracing_subscriber` for binary entry points.
///
/// # Description
/// Sets up a `fmt` subscriber writing to stdout at the requested level. If a subscriber
/// is already registered (e.g. in test harnesses), the error is silently ignored.
///
/// Call this once at the top of `main` before spawning any async tasks.
///
/// # Arguments
/// - `level` (`tracing::Level`): the minimum event level to emit
/// (`TRACE`, `DEBUG`, `INFO`, `WARN`, or `ERROR`).
///
/// # Returns
/// Nothing. Infallible; errors from a double-init are silently discarded.
///
/// # Concurrency
/// May be called from any thread. Only the first call has any effect.
///
/// # Examples
/// ```rust,no_run
/// crypt_guard::log::init_log(tracing::Level::INFO);
/// ```
/// Initialize the logger from a file path — called by the `activate_log` proc-macro.
///
/// # Description
/// Sets up a file-backed `tracing_appender` subscriber that writes structured events
/// to the given path. If a subscriber is already registered, the error is silently
/// ignored (subsequent log events will route to whichever subscriber was installed first).
///
/// # Arguments
/// - `log_file` (`PathBuf`): path to the log file. Parent directories will be created.
///
/// # Returns
/// Nothing. Infallible.
///
/// # Concurrency
/// Same as `init_log`.
///
/// # Examples
/// ```rust,no_run
/// crypt_guard::log::initialize_logger(std::path::PathBuf::from("./crypt.log"));
/// ```