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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
//! Loggit: a zero-setup, color-aware, file-rotating logger for Rust applications.
//!
//! Loggit is a lightweight logging library for Rust that provides built‑in logger macros
//! (such as `trace!`, `debug!`, `info!`, `warn!`, and `error!`) to allow you to start logging
//! with zero boilerplate. You can also customize the log level, format, colors, and output destination.
//!
//! ## Features
//!
//!- **Zero Setup**: Just import the library and start logging.
//!- **Customizable**: Change log formats, colors, and logging levels.
//!- **Macros Provided**: Includes `trace!`, `debug!`, `info!`, `warn!`, and `error!`.
//!- **Flexible Formatting**: Use custom templates with placeholders like `{level}`, `{file}`, `{line}`, and `{message}`.
//!- **Saving log to files**: Save your logs to files automatically by specifying filename format
//!- **File rotation**: Rotate your files by specifying time period or size
//!- **Compress used files**: Save your space by compressing used log files
//!
//! ## Installation
//!
//! Add the following to your Cargo.toml:
//!
//! ```toml
//! [dependencies]
//! loggit = "0.1.9"
//! ```
//!
//! Or use:
//!
//! ```shell
//! cargo add loggit
//! ```
//!
//! ## Usage Examples
//!
//! ### Basic Logging
//!
//! Simply import the logger macros and use it in your project:
//!
//! ````rust
//! use loggit::{trace, debug, info, warn, error};
//!
//! fn main() {
//! trace!("This is a trace message.");
//! debug!("Debug message: variable value = {}", 42);
//! info!("Informational message.");
//! warn!("Warning: something might be off.");
//! error!("Error occurred: {}", "example error");
//! }
//! ````
//!
//! ### Customizing the Log Level
//!
//! Set the minimum log level so that only messages at that level and above are printed:
//!
//! ````rust
//! use loggit::logger::set_log_level;
//! use loggit::Level;
//!
//! fn main() {
//! // Set log level to DEBUG; TRACE messages will be ignored.
//! set_log_level(Level::DEBUG);
//!
//! debug!("This is a debug message.");
//! trace!("This trace message will not be logged.");
//! }
//! ````
//!
//! ### Customizing the Log Format
//!
//! You can adjust the log format globally or per log level. Templates can include placeholders like `{level}`, `{file}`, `{line}`, and `{message}`. Colors can be configured by wrapping text with color tags.
//!
//! **Global Format Customization**
//!
//! ````rust
//! use loggit::logger::set_global_formatting;
//!
//! fn main() {
//! // Set a global custom log format using color tags.
//! set_global_formatting("<green>[{level}]<green> ({file}:{line}) - {message}");
//!
//! info!("This info message follows the new global format.");
//! info!("The error message as well.");
//! }
//! ````
//!
//! **Level-Specific Format Customization**
//!
//! ````rust
//! use loggit::logger::set_level_formatting;
//! use loggit::Level;
//!
//! fn main() {
//! // Customize the ERROR log format specifically.
//! set_level_formatting(
//! Level::ERROR,
//! "<red>[{level}]<red> <blue>({file}:{line})<blue> - <red>{message}<red>"
//! );
//!
//! error!("This error message will follow the custom error format.");
//! }
//! ````
//!
//! ### Enabling Colorized Output
//!
//! Enable or disable colored output based on your preference:
//!
//! ````rust
//! use loggit::logger::set_colorized;
//!
//! fn main() {
//! // Enable colored output.
//! set_colorized(true);
//!
//! info!("This info message will be colorized as specified in the format.");
//! }
//! ````
//!
//! ### Customizing Terminal Output
//!
//! Control whether messages are printed directly to the terminal:
//!
//! ````rust
//! use loggit::logger::set_print_to_terminal;
//!
//! fn main() {
//! // Disable terminal output (for example, if you want to log to a file instead).
//! set_print_to_terminal(false);
//!
//! info!("This message will not be printed to the terminal.");
//! }
//! ````
//!
//! ### Setting up logging to a file
//!
//! Enable saving all your logs to a file
//!
//! ````rust
//! use loggit::logger::set_file;
//!
//! fn main() {
//! // provide file name
//! set_file("file_name.txt");
//! }
//! ````
//!
//! You can choose a format for the file name:
//!
//! ````rust
//! use loggit::logger::set_file;
//!
//! fn main() {
//! // provide file name
//! set_file("{level}-log-on-{date}.txt");
//! }
//! ````
//!
//! Choose how often you change your file
//!
//! ````rust
//! use loggit::logger::{set_file, add_rotation};
//!
//! fn main() {
//! // provide file name
//! set_file("{level}-log-on-{date}.txt");
//! add_rotation("1 week"); // change the file every week
//! add_rotation("5 MB"); // max file size 5 MB, then the file changes again
//! }
//! ````
//!
//! Save your space by compressing log files
//! ```rust
//! use loggit::logger::{set_file, set_compression};
//!
//! fn main() {
//! // provide file name
//! set_file("{level}-log-on-{date}.txt");
//! set_compression("zip");
//! }
//! ```
//!
//! Choose the directory to save archived log files to
//! ```rust
//! use loggit::logger::{set_file, set_compression, set_archive_dir};
//!
//! fn main() {
//! // provide file name
//! set_file("{level}-log-on-{date}.txt");
//! set_compression("zip");
//! set_archive_dir("my_archives"); // all the archives will be stored in the `my_archives` directory
//! }
//! ```
//! ### Configure logger using environment variables
//! ```sh
//! colorized=false file_name="save_here.txt" cargo run
//! ```
//!
//! ### Importing config from files
//! ```rust
//! use loggit::logger::{load_config_from_file};
//!
//! fn main(){
//! let _ = load_config_from_file("my_conf.json");
//! }
//! ```
//!
//! Or simply create a config file with one of those names:
//! - `loggit.env`
//! - `loggit.ini`
//! - `loggit.json`
//!
//! And it will be loaded automatically
//!
//! ## Modules
//!
//! - [`logger`]: Contains functions to control logging configuration and macros to log messages.
use ctor;
use ;
use Lazy;
use ;
use ;
pub
/// Represents the log level used throughout the application.
static CONFIG: = new;