src/logger/builder.rs
Lines
100.00 %
Functions
100.00 %
Regions
99.36 %
| Line | Count | Source (jump to first uncovered line) |
|---|---|---|
| 1 | // | |
| 2 | // File Name: builder.rs | |
| 3 | // Directory: src/logger | |
| 4 | // Project Name: flogging | |
| 5 | // | |
| 6 | // Copyright (C) 2025 Bradley Willcott | |
| 7 | // | |
| 8 | // SPDX-License-Identifier: GPL-3.0-or-later | |
| 9 | // | |
| 10 | // This library (crate) is free software: you can redistribute it and/or modify | |
| 11 | // it under the terms of the GNU General Public License as published by | |
| 12 | // the Free Software Foundation, either version 3 of the License, or | |
| 13 | // (at your option) any later version. | |
| 14 | // | |
| 15 | // This library (crate) is distributed in the hope that it will be useful, | |
| 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 | // GNU General Public License for more details. | |
| 19 | // | |
| 20 | // You should have received a copy of the GNU General Public License | |
| 21 | // along with this library (crate). If not, see <https://www.gnu.org/licenses/>. | |
| 22 | // | |
| 23 | ||
| 24 | //! | |
| 25 | //! # LoggerBuilder | |
| 26 | //! | |
| 27 | ||
| 28 | use crate::*; | |
| 29 | use ::{::, ::,}; | |
| 30 | ||
| 31 | /// | |
| 32 | /// Used by [`Logger`] to provide more flexibility in the configuration of the | |
| 33 | /// final logger. | |
| 34 | /// | |
| 35 | pub struct LoggerBuilder { | |
| 36 | mod_path: | |
| 37 | fn_name: | |
| 38 | level: | |
| 39 | handlers: <<<>>> | |
| 40 | } | |
| 41 | ||
| 42 | impl LoggerBuilder { | |
| 43 | 46 | pub(super) fn create(mod_path:) -> Self { |
| 44 | 46 | { |
| 45 | 46 | , |
| 46 | 46 | : String::(), |
| 47 | 46 | : ::(), |
| 48 | 46 | : ::(::()), |
| 49 | 46 | } |
| 50 | 46 | } |
| 51 | ||
| 52 | /// | |
| 53 | /// Adds a [`ConsoleHandler`] with the default formatter, | |
| 54 | /// with output according to: [`ConsoleType::StdOut`]. | |
| 55 | /// | |
| 56 | /// ## Examples | |
| 57 | /// ``` | |
| 58 | /// extern crate flogging; | |
| 59 | /// use flogging::*; | |
| 60 | /// | |
| 61 | /// let mut log = Logger::builder(module_path!()) | |
| 62 | /// .add_console_handler() | |
| 63 | /// .build(); | |
| 64 | /// ``` | |
| 65 | /// | |
| 66 | 16 | pub fn add_console_handler(self) -> Self { |
| 67 | 16 | selfadd_handler_with(::, None, None, None, None) |
| 68 | 16 | } |
| 69 | ||
| 70 | /// | |
| 71 | /// Adds a [`ConsoleHandler`] with the required formatter, | |
| 72 | /// with output according to: [`ConsoleType::StdOut`]. | |
| 73 | /// | |
| 74 | /// ## Parameters | |
| 75 | /// - `format_type` - The format type used to produce the required formatter. | |
| 76 | /// - `custom_formatter` - The optional boxed custom formatter. | |
| 77 | /// Used by the [`FormatType::Custom`] to produce a [`Formatter::Custom`]. | |
| 78 | /// | |
| 79 | /// ## Examples | |
| 80 | /// First, using a provided formatter: | |
| 81 | /// ``` | |
| 82 | /// extern crate flogging; | |
| 83 | /// use flogging::*; | |
| 84 | /// | |
| 85 | /// let mut log = Logger::builder(module_path!()) | |
| 86 | /// .add_console_handler_with(FormatType::Iso8601, None) | |
| 87 | /// .build(); | |
| 88 | /// ``` | |
| 89 | /// Now using a custom formatter: | |
| 90 | /// ``` | |
| 91 | /// extern crate flogging; | |
| 92 | /// use flogging::*; | |
| 93 | /// | |
| 94 | /// let mut log = Logger::builder(module_path!()) | |
| 95 | /// .add_console_handler_with( | |
| 96 | /// FormatType::Custom, | |
| 97 | /// Some(Box::new(MockFormatter::new())), | |
| 98 | /// ) | |
| 99 | /// .build(); | |
| 100 | /// ``` | |
| 101 | /// | |
| 102 | 2 | pub fn add_console_handler_with( |
| 103 | 2 | self |
| 104 | 2 | format_type: |
| 105 | 2 | custom_formatter: <<>> |
| 106 | 2 | ) -> Self { |
| 107 | 2 | selfadd_handler_with( |
| 108 | 2 | ::, |
| 109 | 2 | None, |
| 110 | 2 | None, |
| 111 | 2 | Some(), |
| 112 | 2 | , |
| 113 | ) | |
| 114 | 2 | } |
| 115 | ||
| 116 | /// | |
| 117 | /// Adds a [`ConsoleHandler`] with the default formatter, | |
| 118 | /// with output according to: [`ConsoleType::StdErr`]. | |
| 119 | /// | |
| 120 | /// ## Examples | |
| 121 | /// ``` | |
| 122 | /// extern crate flogging; | |
| 123 | /// use flogging::*; | |
| 124 | /// | |
| 125 | /// let mut log = Logger::builder(module_path!()) | |
| 126 | /// .add_econsole_handler() | |
| 127 | /// .build(); | |
| 128 | /// ``` | |
| 129 | /// | |
| 130 | 4 | pub fn add_econsole_handler(self) -> Self { |
| 131 | 4 | selfadd_handler_with(::, None, None, None, None) |
| 132 | 4 | } |
| 133 | ||
| 134 | /// | |
| 135 | /// Adds a [`ConsoleHandler`] with the required formatter, | |
| 136 | /// with output according to: [`ConsoleType::StdErr`]. | |
| 137 | /// | |
| 138 | /// ## Parameters | |
| 139 | /// - `format_type` - The format type used to produce the required formatter. | |
| 140 | /// - `custom_formatter` - The optional boxed custom formatter. | |
| 141 | /// Used by the [`FormatType::Custom`] to produce a [`Formatter::Custom`]. | |
| 142 | /// | |
| 143 | /// ## Examples | |
| 144 | /// First, using a provided formatter: | |
| 145 | /// ``` | |
| 146 | /// extern crate flogging; | |
| 147 | /// use flogging::*; | |
| 148 | /// | |
| 149 | /// let mut log = Logger::builder(module_path!()) | |
| 150 | /// .add_econsole_handler_with(FormatType::Iso8601, None) | |
| 151 | /// .build(); | |
| 152 | /// ``` | |
| 153 | /// Now using a custom formatter: | |
| 154 | /// ``` | |
| 155 | /// extern crate flogging; | |
| 156 | /// use flogging::*; | |
| 157 | /// | |
| 158 | /// let mut log = Logger::builder(module_path!()) | |
| 159 | /// .add_econsole_handler_with( | |
| 160 | /// FormatType::Custom, | |
| 161 | /// Some(Box::new(MockFormatter::new())), | |
| 162 | /// ) | |
| 163 | /// .build(); | |
| 164 | /// ``` | |
| 165 | /// | |
| 166 | 2 | pub fn add_econsole_handler_with( |
| 167 | 2 | self |
| 168 | 2 | format_type: |
| 169 | 2 | custom_formatter: <<>> |
| 170 | 2 | ) -> Self { |
| 171 | 2 | selfadd_handler_with( |
| 172 | 2 | ::, |
| 173 | 2 | None, |
| 174 | 2 | None, |
| 175 | 2 | Some(), |
| 176 | 2 | , |
| 177 | ) | |
| 178 | 2 | } |
| 179 | ||
| 180 | /// | |
| 181 | /// Adds a custom handler with the default formatter. | |
| 182 | /// | |
| 183 | /// ## Parameters | |
| 184 | /// - `label` - Unique identifier for this custom handler. Used when attempting to | |
| 185 | /// retrieve this handler: [`has_handler()`][Logger::has_handler], [`get_handler()`][Logger::get_handler] | |
| 186 | /// - `custom_handler` - The boxed custom handler. | |
| 187 | /// | |
| 188 | /// ## Examples | |
| 189 | /// ``` | |
| 190 | /// extern crate flogging; | |
| 191 | /// use flogging::*; | |
| 192 | /// | |
| 193 | /// let mut log = Logger::builder(module_path!()) | |
| 194 | /// .add_custom_handler( | |
| 195 | /// "MockHandler", | |
| 196 | /// Box::new(MockHandler::create("What ever you need").unwrap()), | |
| 197 | /// ) | |
| 198 | /// .build(); | |
| 199 | /// ``` | |
| 200 | /// | |
| 201 | 3 | pub fn add_custom_handler(selflabel: &strcustom_handler: <>) -> Self { |
| 202 | 3 | selfadd_handler_with( |
| 203 | 3 | ::(to_string()), |
| 204 | 3 | Some(), |
| 205 | 3 | None, |
| 206 | 3 | None, |
| 207 | 3 | None, |
| 208 | ) | |
| 209 | 3 | } |
| 210 | ||
| 211 | /// | |
| 212 | /// Adds a custom handler with the required formatter. | |
| 213 | /// | |
| 214 | /// ## Parameters | |
| 215 | /// - `label` - Unique identifier for this custom handler. Used when attempting to | |
| 216 | /// retrieve this handler: [`has_handler()`][Logger::has_handler], [`get_handler()`][Logger::get_handler] | |
| 217 | /// - `custom_handler` - The boxed custom handler. | |
| 218 | /// - `format_type` - The format type used to produce the required formatter. | |
| 219 | /// - `custom_formatter` - The optional boxed custom formatter. | |
| 220 | /// Used by the [`FormatType::Custom`] to produce a [`Formatter::Custom`]. | |
| 221 | /// | |
| 222 | /// ## Examples | |
| 223 | /// First, using a provided formatter: | |
| 224 | /// ``` | |
| 225 | /// extern crate flogging; | |
| 226 | /// use flogging::*; | |
| 227 | /// | |
| 228 | /// let mut log = Logger::builder(module_path!()) | |
| 229 | /// .add_custom_handler_with( | |
| 230 | /// "MockHandler", | |
| 231 | /// Box::new(MockHandler::create("What ever you need").unwrap()), | |
| 232 | /// FormatType::Simple, | |
| 233 | /// None, | |
| 234 | /// ) | |
| 235 | /// .build(); | |
| 236 | /// ``` | |
| 237 | /// Now using a custom formatter: | |
| 238 | /// ``` | |
| 239 | /// extern crate flogging; | |
| 240 | /// use flogging::*; | |
| 241 | /// | |
| 242 | /// let mut log = Logger::builder(module_path!()) | |
| 243 | /// .add_custom_handler_with( | |
| 244 | /// "MockHandler", | |
| 245 | /// Box::new(MockHandler::create("What ever you need").unwrap()), | |
| 246 | /// FormatType::Custom, | |
| 247 | /// Some(Box::new(MockFormatter::new())), | |
| 248 | /// ) | |
| 249 | /// .build(); | |
| 250 | /// ``` | |
| 251 | /// | |
| 252 | 2 | pub fn add_custom_handler_with( |
| 253 | 2 | self |
| 254 | 2 | label: &str |
| 255 | 2 | custom_handler: <> |
| 256 | 2 | format_type: |
| 257 | 2 | custom_formatter: <<>> |
| 258 | 2 | ) -> Self { |
| 259 | 2 | selfadd_handler_with( |
| 260 | 2 | ::(to_string()), |
| 261 | 2 | Some(), |
| 262 | 2 | None, |
| 263 | 2 | Some(), |
| 264 | 2 | , |
| 265 | ) | |
| 266 | 2 | } |
| 267 | ||
| 268 | /// | |
| 269 | /// Adds a [`FileHandler`] with the default formatter. | |
| 270 | /// | |
| 271 | /// ## Parameters | |
| 272 | /// | |
| 273 | /// - `filename` - The name of the output log file. Must include any relevant | |
| 274 | /// path (relative or absolute). | |
| 275 | /// | |
| 276 | /// ## Examples | |
| 277 | /// ``` | |
| 278 | /// extern crate flogging; | |
| 279 | /// use flogging::*; | |
| 280 | /// | |
| 281 | /// let mut log = Logger::builder(module_path!()) | |
| 282 | /// .add_file_handler("test_logs/builder.log") | |
| 283 | /// .build(); | |
| 284 | /// ``` | |
| 285 | /// | |
| 286 | 17 | pub fn add_file_handler(selffilename: &str) -> Self { |
| 287 | 17 | selfadd_handler_with(::, None, Some(), None, None) |
| 288 | 17 | } |
| 289 | ||
| 290 | /// | |
| 291 | /// Adds a [`FileHandler`] with the required formatter. | |
| 292 | /// | |
| 293 | /// ## Parameters | |
| 294 | /// - `filename` - The name of the output log file. Must include any relevant | |
| 295 | /// path (relative or absolute). | |
| 296 | /// - `format_type` - The format type used to produce the required formatter. | |
| 297 | /// - `custom_formatter` - The optional boxed custom formatter. | |
| 298 | /// Used by the [`FormatType::Custom`] to produce a [`Formatter::Custom`]. | |
| 299 | /// | |
| 300 | /// ## Examples | |
| 301 | /// First, using a provided formatter: | |
| 302 | /// ``` | |
| 303 | /// extern crate flogging; | |
| 304 | /// use flogging::*; | |
| 305 | /// | |
| 306 | /// let mut log = Logger::builder(module_path!()) | |
| 307 | /// .add_file_handler_with("test_logs/builder.log", FormatType::Iso8601, None) | |
| 308 | /// .build(); | |
| 309 | /// ``` | |
| 310 | /// Now using a custom formatter: | |
| 311 | /// ``` | |
| 312 | /// extern crate flogging; | |
| 313 | /// use flogging::*; | |
| 314 | /// | |
| 315 | /// let mut log = Logger::builder(module_path!()) | |
| 316 | /// .add_file_handler_with( | |
| 317 | /// "test_logs/builder.log", | |
| 318 | /// FormatType::Custom, | |
| 319 | /// Some(Box::new(MockFormatter::new())), | |
| 320 | /// ) | |
| 321 | /// .build(); | |
| 322 | /// ``` | |
| 323 | /// | |
| 324 | 3 | pub fn add_file_handler_with( |
| 325 | 3 | self |
| 326 | 3 | filename: &str |
| 327 | 3 | format_type: |
| 328 | 3 | custom_formatter: <<>> |
| 329 | 3 | ) -> Self { |
| 330 | 3 | selfadd_handler_with( |
| 331 | 3 | ::, |
| 332 | 3 | None, |
| 333 | 3 | Some(), |
| 334 | 3 | Some(), |
| 335 | 3 | , |
| 336 | ) | |
| 337 | 3 | } |
| 338 | ||
| 339 | 65 | fn add_handler_with( |
| 340 | 65 | mut self |
| 341 | 65 | handler: |
| 342 | 65 | custom_handler: <<>> |
| 343 | 65 | filename: <&str> |
| 344 | 65 | format_type: <> |
| 345 | 65 | custom_formatter: <<>> |
| 346 | 65 | ) -> Self { |
| 347 | 65 | let=unwrap_or(&self); |
| 348 | 65 | let mut: <> = match{ |
| 349 | ::=> { | |
| 350 | 18 | Box::(::(::as_str())unwrap()) |
| 351 | } | |
| 352 | ::=> { | |
| 353 | 6 | Box::(::(::as_str())unwrap()) |
| 354 | } | |
| 355 | 20 | ::=> Box::(::()unwrap()), |
| 356 | ::=> { | |
| 357 | 4 | Box::(::(::as_str())unwrap()) |
| 358 | } | |
| 359 | 12 | ::=> Box::(::()unwrap()), |
| 360 | 5 | ::(_) =>unwrap(), |
| 361 | }; | |
| 362 | ||
| 363 | 65 | if let Some() ={ |
| 364 | 12 | set_formatter(match{ |
| 365 | 5 | ::=>create(None), |
| 366 | 3 | ::=>create(None), |
| 367 | 1 | ::=>create(None), |
| 368 | 3 | ::=>create(), |
| 369 | }); | |
| 370 | 53 | } |
| 371 | ||
| 372 | 65 | let= selfget_mut(); |
| 373 | 65 | insert(,); |
| 374 | ||
| 375 | 65 | self |
| 376 | 65 | } |
| 377 | ||
| 378 | /// | |
| 379 | /// Adds a [`ConsoleHandler`] with the default formatter, | |
| 380 | /// with output according to: [`ConsoleType::Production`]. | |
| 381 | /// | |
| 382 | /// ## Examples | |
| 383 | /// ``` | |
| 384 | /// extern crate flogging; | |
| 385 | /// use flogging::*; | |
| 386 | /// | |
| 387 | /// let mut log = Logger::builder(module_path!()) | |
| 388 | /// .add_pconsole_handler() | |
| 389 | /// .build(); | |
| 390 | /// ``` | |
| 391 | /// | |
| 392 | 3 | pub fn add_pconsole_handler(self) -> Self { |
| 393 | 3 | selfadd_handler_with(::, None, None, None, None) |
| 394 | 3 | } |
| 395 | ||
| 396 | /// | |
| 397 | /// Adds a [`ConsoleHandler`] with the required formatter, | |
| 398 | /// with output according to: [`ConsoleType::Production`]. | |
| 399 | /// | |
| 400 | /// ## Parameters | |
| 401 | /// - `format_type` - The format type used to produce the required formatter. | |
| 402 | /// - `custom_formatter` - The optional boxed custom formatter. | |
| 403 | /// Used by the [`FormatType::Custom`] to produce a [`Formatter::Custom`]. | |
| 404 | /// | |
| 405 | /// ## Examples | |
| 406 | /// First, using a provided formatter: | |
| 407 | /// ``` | |
| 408 | /// extern crate flogging; | |
| 409 | /// use flogging::*; | |
| 410 | /// | |
| 411 | /// let mut log = Logger::builder(module_path!()) | |
| 412 | /// .add_pconsole_handler_with(FormatType::Iso8601, None) | |
| 413 | /// .build(); | |
| 414 | /// ``` | |
| 415 | /// Now using a custom formatter: | |
| 416 | /// ``` | |
| 417 | /// extern crate flogging; | |
| 418 | /// use flogging::*; | |
| 419 | /// | |
| 420 | /// let mut log = Logger::builder(module_path!()) | |
| 421 | /// .add_pconsole_handler_with( | |
| 422 | /// FormatType::Custom, | |
| 423 | /// Some(Box::new(MockFormatter::new())), | |
| 424 | /// ) | |
| 425 | /// .build(); | |
| 426 | /// ``` | |
| 427 | /// | |
| 428 | 1 | pub fn add_pconsole_handler_with( |
| 429 | 1 | self |
| 430 | 1 | format_type: |
| 431 | 1 | custom_formatter: <<>> |
| 432 | 1 | ) -> Self { |
| 433 | 1 | selfadd_handler_with( |
| 434 | 1 | ::, |
| 435 | 1 | None, |
| 436 | 1 | None, |
| 437 | 1 | Some(), |
| 438 | 1 | , |
| 439 | ) | |
| 440 | 1 | } |
| 441 | ||
| 442 | /// | |
| 443 | /// Adds a [`StringHandler`] with the default formatter. | |
| 444 | /// | |
| 445 | /// ## Examples | |
| 446 | /// ``` | |
| 447 | /// extern crate flogging; | |
| 448 | /// use flogging::*; | |
| 449 | /// | |
| 450 | /// let mut log = Logger::builder(module_path!()) | |
| 451 | /// .add_string_handler() | |
| 452 | /// .build(); | |
| 453 | /// ``` | |
| 454 | /// | |
| 455 | 11 | pub fn add_string_handler(self) -> Self { |
| 456 | 11 | selfadd_handler_with(::, None, None, None, None) |
| 457 | 11 | } |
| 458 | ||
| 459 | /// | |
| 460 | /// Adds a [`StringHandler`] with the required formatter. | |
| 461 | /// | |
| 462 | /// ## Parameters | |
| 463 | /// - `format_type` - The format type used to produce the required formatter. | |
| 464 | /// - `custom_formatter` - The optional boxed custom formatter. | |
| 465 | /// Used by the [`FormatType::Custom`] to produce a [`Formatter::Custom`]. | |
| 466 | /// | |
| 467 | /// ## Examples | |
| 468 | /// First, using a provided formatter: | |
| 469 | /// ``` | |
| 470 | /// extern crate flogging; | |
| 471 | /// use flogging::*; | |
| 472 | /// | |
| 473 | /// let mut log = Logger::builder(module_path!()) | |
| 474 | /// .add_string_handler_with(FormatType::Iso8601, None) | |
| 475 | /// .build(); | |
| 476 | /// ``` | |
| 477 | /// Now using a custom formatter: | |
| 478 | /// ``` | |
| 479 | /// extern crate flogging; | |
| 480 | /// use flogging::*; | |
| 481 | /// | |
| 482 | /// let mut log = Logger::builder(module_path!()) | |
| 483 | /// .add_string_handler_with( | |
| 484 | /// FormatType::Custom, | |
| 485 | /// Some(Box::new(MockFormatter::new())), | |
| 486 | /// ) | |
| 487 | /// .build(); | |
| 488 | /// ``` | |
| 489 | /// | |
| 490 | 1 | pub fn add_string_handler_with( |
| 491 | 1 | self |
| 492 | 1 | format_type: |
| 493 | 1 | custom_formatter: <<>> |
| 494 | 1 | ) -> Self { |
| 495 | 1 | selfadd_handler_with( |
| 496 | 1 | ::, |
| 497 | 1 | None, |
| 498 | 1 | None, |
| 499 | 1 | Some(), |
| 500 | 1 | , |
| 501 | ) | |
| 502 | 1 | } |
| 503 | ||
| 504 | /// | |
| 505 | /// Complete the build process and produce the final [`Logger`] instance. | |
| 506 | /// | |
| 507 | /// ## Examples | |
| 508 | /// ``` | |
| 509 | /// extern crate flogging; | |
| 510 | /// use flogging::*; | |
| 511 | /// | |
| 512 | /// let mut log = Logger::builder(module_path!()) | |
| 513 | /// .add_console_handler() | |
| 514 | /// .build(); | |
| 515 | /// ``` | |
| 516 | /// | |
| 517 | 45 | pub fn build(self) -> { |
| 518 | 45 | { |
| 519 | 45 | : selfclone(), |
| 520 | 45 | : selfclone(), |
| 521 | 45 | : self, |
| 522 | 45 | : self, |
| 523 | 45 | } |
| 524 | 45 | } |
| 525 | ||
| 526 | /// | |
| 527 | /// Remove an existing log file. | |
| 528 | /// | |
| 529 | /// The purpose of this, is to allow resetting of the log file, each time | |
| 530 | /// a test run is done. | |
| 531 | /// | |
| 532 | /// ## Note | |
| 533 | /// | |
| 534 | /// This **must** be called _before_ adding the corresponding file handler | |
| 535 | /// that is going to open this file. | |
| 536 | /// | |
| 537 | /// ## Parameters | |
| 538 | /// | |
| 539 | /// - `filename` - The name of the output log file. Must include any relevant | |
| 540 | /// path (relative or absolute). | |
| 541 | /// | |
| 542 | /// ## Examples | |
| 543 | /// ``` | |
| 544 | /// extern crate flogging; | |
| 545 | /// use flogging::*; | |
| 546 | /// | |
| 547 | /// let mut log = Logger::builder(module_path!()) | |
| 548 | /// .remove_file("test_logs/builder.log") | |
| 549 | /// .add_file_handler("test_logs/builder.log") | |
| 550 | /// .build(); | |
| 551 | /// ``` | |
| 552 | /// | |
| 553 | 14 | pub fn remove_file(selffilename: &str) -> Self { |
| 554 | 14 | let _ = ::()is_err(); |
| 555 | 14 | self |
| 556 | 14 | } |
| 557 | ||
| 558 | /// | |
| 559 | /// Set the current function/method name. | |
| 560 | /// | |
| 561 | /// ## Parameters | |
| 562 | /// - `fn_name` - The name of the function/method in which you are | |
| 563 | /// logging. | |
| 564 | /// | |
| 565 | /// Returns itself for chaining purposes. | |
| 566 | /// | |
| 567 | 15 | pub fn set_fn_name(mut selffn_name: &str) -> Self { |
| 568 | 15 | self=to_string(); |
| 569 | 15 | self |
| 570 | 15 | } |
| 571 | ||
| 572 | /// | |
| 573 | /// Set the logging level for the [`Logger`] instance being configured. | |
| 574 | /// | |
| 575 | /// ## Parameters | |
| 576 | /// - `level` - The new level to set. | |
| 577 | /// | |
| 578 | /// ## Examples | |
| 579 | /// ``` | |
| 580 | /// extern crate flogging; | |
| 581 | /// use flogging::*; | |
| 582 | /// | |
| 583 | /// let mut log = Logger::builder(module_path!()) | |
| 584 | /// .add_console_handler() | |
| 585 | /// .set_level(Level::ALL) | |
| 586 | /// .build(); | |
| 587 | /// ``` | |
| 588 | /// | |
| 589 | 14 | pub fn set_level(mut selflevel:) -> Self { |
| 590 | 14 | self=; |
| 591 | 14 | self |
| 592 | 14 | } |
| 593 | } | |
| 594 | ||
| 595 | #[cfg()] | |
| 596 | mod tests { | |
| 597 | use crate::*; | |
| 598 | use ::; | |
| 599 | use ::::{Result,,,}; | |
| 600 | ||
| 601 | #[test] | |
| 602 | 1 | fn temp() -> <()> { |
| 603 | 1 | let= "arguments"; |
| 604 | 1 | let mut= stdout(); |
| 605 | 1 | writeln!( |
| 606 | 1 | "test")?; |
| 607 | 1 | writeln!( "formatted {}",)?; |
| 608 | ||
| 609 | // assert_eq!(&w[..], "\ntest\nformatted arguments\n".as_bytes()); | |
| 610 | 1 | Ok(()) |
| 611 | 1 | } |
| 612 | #[test] | |
| 613 | 1 | fn add_console_handler() { |
| 614 | 1 | let= "flogging::logger::builder::tests->add_console_handler [INFO ] We begin! |
| 615 | 1 | flogging::logger::builder::tests->add_console_handler [WARNING] Need more tests. |
| 616 | 1 | " |
| 617 | 1 | to_string(); |
| 618 | ||
| 619 | 1 | let mut= ::(module_path!()) |
| 620 | 1 | add_console_handler() |
| 621 | 1 | set_fn_name("add_console_handler") |
| 622 | 1 | build(); |
| 623 | ||
| 624 | 1 | let=get_handler(crate::::)unwrap(); |
| 625 | 1 | set_test_mode(true); |
| 626 | ||
| 627 | 1 | info("We begin!"); |
| 628 | 1 | warning("Need more tests."); |
| 629 | ||
| 630 | 1 | let=get_handler(crate::::)unwrap(); |
| 631 | 1 | let=get_log(); |
| 632 | 1 | assert_eq!(,); |
| 633 | 1 | } |
| 634 | ||
| 635 | #[test] | |
| 636 | 1 | fn add_console_handler_with() { |
| 637 | 1 | let= |
| 638 | 1 | "^(?:\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{9}\\+\\d{2}:\\d{2}) flogging::logger::builder::tests->add_console_handler_with \\[INFO ] We begin! |
| 639 | 1 | (?:\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{9}\\+\\d{2}:\\d{2}) flogging::logger::builder::tests->add_console_handler_with \\[WARNING] Need more tests. |
| 640 | 1 | $"; |
| 641 | ||
| 642 | 1 | let= ::()unwrap(); |
| 643 | ||
| 644 | 1 | let mut= ::(module_path!()) |
| 645 | 1 | add_console_handler_with(::, None) |
| 646 | 1 | set_fn_name("add_console_handler_with") |
| 647 | 1 | build(); |
| 648 | ||
| 649 | 1 | let=get_handler(crate::::)unwrap(); |
| 650 | 1 | set_test_mode(true); |
| 651 | ||
| 652 | 1 | info("We begin!"); |
| 653 | 1 | warning("Need more tests."); |
| 654 | ||
| 655 | 1 | let=get_handler(crate::::)unwrap(); |
| 656 | 1 | let=get_log(); |
| 657 | 1 | println!("{result}"); |
| 658 | ||
| 659 | 1 | assert!(is_match(&)); |
| 660 | 1 | } |
| 661 | ||
| 662 | #[test] | |
| 663 | 1 | fn add_econsole_handler() { |
| 664 | 1 | let mut= ::(module_path!()) |
| 665 | 1 | add_econsole_handler() |
| 666 | 1 | set_fn_name("add_econsole_handler") |
| 667 | 1 | build(); |
| 668 | ||
| 669 | 1 | info("We begin!"); |
| 670 | 1 | warning("Need more tests."); |
| 671 | 1 | } |
| 672 | ||
| 673 | #[test] | |
| 674 | 1 | fn add_econsole_handler_with() { |
| 675 | 1 | let mut= ::(module_path!()) |
| 676 | 1 | add_econsole_handler_with(::, None) |
| 677 | 1 | set_fn_name("add_econsole_handler_with") |
| 678 | 1 | build(); |
| 679 | ||
| 680 | 1 | info("We begin!"); |
| 681 | 1 | warning("Need more tests."); |
| 682 | 1 | } |
| 683 | ||
| 684 | #[test] | |
| 685 | 1 | fn add_custom_handler() { |
| 686 | 1 | let mut= ::(module_path!()) |
| 687 | 1 | add_custom_handler( |
| 688 | 1 | "Console", |
| 689 | 1 | Box::(::(::as_str())unwrap()), |
| 690 | ) | |
| 691 | 1 | set_fn_name("add_custom_handler") |
| 692 | 1 | build(); |
| 693 | ||
| 694 | 1 | info("We begin!"); |
| 695 | 1 | warning("Need more tests."); |
| 696 | 1 | } |
| 697 | ||
| 698 | #[test] | |
| 699 | 1 | fn add_custom_handler_with() { |
| 700 | 1 | let mut= ::(module_path!()) |
| 701 | 1 | add_custom_handler_with( |
| 702 | 1 | "Console", |
| 703 | 1 | Box::(::(::as_str())unwrap()), |
| 704 | 1 | ::, |
| 705 | 1 | Some(Box::(::())), |
| 706 | ) | |
| 707 | 1 | set_fn_name("add_custom_handler_with") |
| 708 | 1 | build(); |
| 709 | ||
| 710 | 1 | info("We begin!"); |
| 711 | 1 | warning("Need more tests."); |
| 712 | 1 | } |
| 713 | ||
| 714 | #[test] | |
| 715 | 1 | fn add_file_handler() { |
| 716 | 1 | let mut= ::(module_path!()) |
| 717 | 1 | add_file_handler("test_logs/add_file_handler.log") |
| 718 | 1 | set_fn_name("add_file_handler") |
| 719 | 1 | build(); |
| 720 | ||
| 721 | 1 | info("We begin!"); |
| 722 | 1 | warning("Need more tests."); |
| 723 | 1 | } |
| 724 | ||
| 725 | #[test] | |
| 726 | 1 | fn add_file_handler_with() { |
| 727 | 1 | let mut= ::(module_path!()) |
| 728 | 1 | add_file_handler_with( |
| 729 | 1 | "test_logs/add_file_handler_with.log", |
| 730 | 1 | crate::::, |
| 731 | 1 | None, |
| 732 | ) | |
| 733 | 1 | set_fn_name("add_file_handler_with") |
| 734 | 1 | build(); |
| 735 | ||
| 736 | 1 | info("We begin!"); |
| 737 | 1 | warning("Need more tests."); |
| 738 | 1 | } |
| 739 | ||
| 740 | #[test] | |
| 741 | 1 | fn add_pconsole_handler() { |
| 742 | 1 | let mut= ::(module_path!()) |
| 743 | 1 | add_pconsole_handler() |
| 744 | 1 | set_fn_name("add_pconsole_handler") |
| 745 | 1 | build(); |
| 746 | ||
| 747 | 1 | info("We begin!"); |
| 748 | 1 | warning("Need more tests."); |
| 749 | 1 | } |
| 750 | ||
| 751 | #[test] | |
| 752 | 1 | fn add_pconsole_handler_with() { |
| 753 | 1 | let mut= ::(module_path!()) |
| 754 | 1 | add_pconsole_handler_with(::, None) |
| 755 | 1 | set_fn_name("add_pconsole_handler_with") |
| 756 | 1 | build(); |
| 757 | ||
| 758 | 1 | info("We begin!"); |
| 759 | 1 | warning("Need more tests."); |
| 760 | 1 | } |
| 761 | ||
| 762 | #[test] | |
| 763 | 1 | fn add_string_handler() { |
| 764 | 1 | let mut= ::(module_path!()) |
| 765 | 1 | add_string_handler() |
| 766 | 1 | set_fn_name("add_string_handler") |
| 767 | 1 | build(); |
| 768 | ||
| 769 | 1 | info("We begin!"); |
| 770 | 1 | warning("Need more tests."); |
| 771 | 1 | } |
| 772 | ||
| 773 | #[test] | |
| 774 | 1 | fn add_string_handler_with() { |
| 775 | 1 | let mut= ::(module_path!()) |
| 776 | 1 | add_string_handler_with(crate::::, None) |
| 777 | 1 | set_fn_name("add_string_handler_with") |
| 778 | 1 | build(); |
| 779 | ||
| 780 | 1 | info("We begin!"); |
| 781 | 1 | warning("Need more tests."); |
| 782 | 1 | } |
| 783 | ||
| 784 | #[test] | |
| 785 | 1 | fn remove_file() { |
| 786 | 1 | let mut= ::(module_path!()) |
| 787 | 1 | remove_file("test_logs/remove_file.log") |
| 788 | 1 | add_file_handler("test_logs/remove_file.log") |
| 789 | 1 | set_fn_name("add_file_handler") |
| 790 | 1 | build(); |
| 791 | ||
| 792 | 1 | info("We begin!"); |
| 793 | 1 | warning("Need more tests."); |
| 794 | 1 | } |
| 795 | } |