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
// License: see LICENSE file at root directory of `master` branch

//! # Simple logging kit
//!
//! ## Project
//!
//! - Repository: <https://bitbucket.org/haibison/ice-age>
//! - License: Nice License 1.0.0 _(see LICENSE file at root directory of `master` branch)_
//! - _This project follows [Semantic Versioning 2.0.0]_
//!
//! ---
//!
//! ## Design
//!
//! It uses [synchronous channels][r::sync_channel] for communication. Log records are stored in RAM, and will be flushed to
//! disk based on some configurable conditions: a period of time, or when maximum number of records reached.
//!
//! Backends: SQLite.
//!
//! The crate's own log messages are prefixed with [`TAG`][::TAG].
//!
//! ## Examples
//!
//! ```
//! use std::{
//!     env,
//!     sync::mpsc::TrySendError,
//!     thread,
//!     time::{UNIX_EPOCH, Duration, SystemTime},
//! };
//! use ice_age::{Config, Cmd, Log, Logger};
//!
//! let config = Config {
//!     // Directory to save log files
//!     work_dir: env::temp_dir(),
//!     // For this example, max file length is 1 MiB
//!     max_file_len: 1024 * 1024,
//!     // Keep log files at most 3 days
//!     log_files_reserved: Duration::from_secs(3 * 24 * 60 * 60),
//!     // Maximum log records to be kept in RAM
//!     buf_len: 5_000,
//!     // Flush to disk every 30 minutes
//!     disk_flush_interval: Duration::from_secs(30 * 60),
//! };
//!
//! let logger = Logger::make(config).unwrap();
//! for _ in 0..3 {
//!     let logger = logger.clone();
//!     thread::spawn(move || {
//!         let log = Log {
//!             time: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(),
//!             remote_ip: String::from("127.0.0.1"),
//!             url: String::from("/api/statistics"),
//!             response_size: Some(512),
//!             code: 200,
//!             runtime: Duration::from_secs(1),
//!             notes: None,
//!         };
//!
//!         // Use ::try_send() to not block the thread.
//!         // This example's strategy is to discard failed calls.
//!         match logger.try_send(Cmd::StoreLog(log)) {
//!             Ok(()) => (),
//!             Err(TrySendError::Full(_)) =>
//!                 eprintln!("Log buffer is full, discarding..."),
//!             Err(TrySendError::Disconnected(_)) =>
//!                 eprintln!("Failed to store log. Perhaps log server is down."),
//!         };
//!     });
//! }
//! ```
//!
//! [Semantic Versioning 2.0.0]: https://semver.org/spec/v2.0.0.html
//! [::TAG]: constant.TAG.html
//! [r::sync_channel]: https://doc.rust-lang.org/std/sync/mpsc/fn.sync_channel.html

#[macro_use]
#[allow(unused_macros)]
mod __;
mod root;

pub mod version_info;

pub use root::*;

// ╔═════════════════╗
// ║   IDENTIFIERS   ║
// ╚═════════════════╝

macro_rules! code_name  { () => { "ice-age" }}
macro_rules! version    { () => { "0.13.0" }}

/// # Crate name
pub const NAME: &str = "Ice Age";

/// # Crate code name
pub const CODE_NAME: &str = code_name!();

/// # ID of this crate
pub const ID: &str = concat!(
    "025f3a9e-9bc88f1d-8a8a6b9a-9a00e3d5-10b76338-67eb660c-10560cf2-d8049819-",
    "bebdff98-b9883fd2-17155b4f-b85e3ccd-02b818ac-18f9bcbc-e76c778a-53a0e376",
);

/// # Crate version
pub const VERSION: &str = version!();

/// # Crate release date (year/month/day)
pub const RELEASE_DATE: (u16, u8, u8) = (2019, 6, 13);

/// # Tag, which can be used for logging...
pub const TAG: &str = concat!(code_name!(), "::025f3a9e::", version!());

// ╔════════════════════╗
// ║   IMPLEMENTATION   ║
// ╚════════════════════╝

#[test]
fn test_crate_version() {
    assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
}