#![cfg_attr(not(feature = "std"), feature(alloc))]
#![cfg_attr(not(feature = "std"), feature(collections))]
#![warn(missing_docs)]
#![no_std]
#[macro_use]
#[cfg(feature = "std")]
extern crate std;
#[cfg(not(feature = "std"))]
extern crate alloc;
#[cfg(not(feature = "std"))]
extern crate collections;
use core::str::FromStr;
use core::fmt;
use core::result;
#[cfg(feature = "std")]
use std::sync::Arc;
#[cfg(not(feature = "std"))]
use alloc::arc::Arc;
#[cfg(feature = "std")]
use std::slice;
#[cfg(not(feature = "std"))]
use core::slice;
#[cfg(feature = "std")]
use std::vec::Vec;
#[cfg(not(feature = "std"))]
use collections::vec::Vec;
#[cfg(feature = "std")]
use std::boxed::Box;
#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
#[doc(hidden)]
pub type Never = ();
#[cfg(feature = "std")]
#[macro_export]
macro_rules! o(
() => {
vec![]
};
($($k:expr => $v:expr),*) => {
{
vec![$(($k, ::std::boxed::Box::new($v))),*]
}
};
($($k:expr => $v:expr),*,) => {
{
o!($($k => $v),*)
}
};
);
#[cfg(not(feature = "std"))]
#[macro_export]
macro_rules! o(
() => {
vec![]
};
($($k:expr => $v:expr),*) => {
{
use alloc;
vec![$(($k, alloc::boxed::Box::new($v))),*]
}
};
($($k:expr => $v:expr),*,) => {
{
o!($($k => $v),*)
}
};
);
#[macro_export]
macro_rules! log(
($lvl:expr, $l:expr, $($k:expr => $v:expr),*; $($args:tt)+ ) => {
if $lvl.as_usize() <= $crate::__slog_static_max_level().as_usize() {
static RS : $crate::RecordStatic<'static> = $crate::RecordStatic {
level: $lvl,
file: file!(),
line: line!(),
column: column!(),
function: "",
module: module_path!(),
target: module_path!(),
};
$l.log(&$crate::Record::new(&RS, format_args!($($args)+), &[$(($k, &$v)),*]))
}
};
($lvl:expr, $l:expr, $($args:tt),+) => {
if $lvl.as_usize() <= $crate::__slog_static_max_level().as_usize() {
static RS : $crate::RecordStatic<'static> = $crate::RecordStatic {
level: $lvl,
file: file!(),
line: line!(),
column: column!(),
function: "",
module: module_path!(),
target: module_path!(),
};
$l.log(&$crate::Record::new(&RS, format_args!($($args),+), &[]))
}
};
($lvl:expr, $l:expr, $($args:tt),+,) => {
log!($lvl, $l, $($args),+)
};
($lvl:expr, $l:expr, $msg:expr) => {
if $lvl.as_usize() <= $crate::__slog_static_max_level().as_usize() {
static RS : $crate::RecordStatic<'static> = $crate::RecordStatic {
level: $lvl,
file: file!(),
line: line!(),
column: column!(),
function: "",
module: module_path!(),
target: module_path!(),
};
$l.log(&$crate::Record::new(&RS, format_args!("{}", $msg), &[]))
}
};
($lvl:expr, $l:expr, $msg:expr; $($k:expr => $v:expr),*) => {
if $lvl.as_usize() <= $crate::__slog_static_max_level().as_usize() {
static RS : $crate::RecordStatic<'static> = $crate::RecordStatic {
level: $lvl,
file: file!(),
line: line!(),
column: column!(),
function: "",
module: module_path!(),
target: module_path!(),
};
$l.log(&$crate::Record::new(&RS, format_args!("{}", $msg), &[$(($k, &$v)),*]))
}
};
($lvl:expr, $l:expr, $msg:expr; $($k:expr => $v:expr),*,) => {
log!($lvl, $l, $msg; $($k => $v),*)
};
);
#[macro_export]
macro_rules! slog_log(
($lvl:expr, $l:expr, $($k:expr => $v:expr),*; $($args:tt)+ ) => {
if $lvl.as_usize() <= $crate::__slog_static_max_level().as_usize() {
static RS : $crate::RecordStatic<'static> = $crate::RecordStatic {
level: $lvl,
file: file!(),
line: line!(),
column: column!(),
function: "",
module: module_path!(),
target: module_path!(),
};
$l.log(&$crate::Record::new(&RS, format_args!($($args)+), &[$(($k, &$v)),*]))
}
};
($lvl:expr, $l:expr, $($args:tt),+) => {
if $lvl.as_usize() <= $crate::__slog_static_max_level().as_usize() {
static RS : $crate::RecordStatic<'static> = $crate::RecordStatic {
level: $lvl,
file: file!(),
line: line!(),
column: column!(),
function: "",
module: module_path!(),
target: module_path!(),
};
$l.log(&$crate::Record::new(&RS, format_args!($($args),+), &[]))
}
};
($lvl:expr, $l:expr, $($args:tt),+,) => {
slog_log!($lvl, $l, $($args),+)
};
($lvl:expr, $l:expr, $msg:expr) => {
if $lvl.as_usize() <= $crate::__slog_static_max_level().as_usize() {
static RS : $crate::RecordStatic<'static> = $crate::RecordStatic {
level: $lvl,
file: file!(),
line: line!(),
column: column!(),
function: "",
module: module_path!(),
target: module_path!(),
};
$l.log(&$crate::Record::new(&RS, format_args!("{}", $msg), &[]))
}
};
($lvl:expr, $l:expr, $msg:expr; $($k:expr => $v:expr),*) => {
if $lvl.as_usize() <= $crate::__slog_static_max_level().as_usize() {
static RS : $crate::RecordStatic<'static> = $crate::RecordStatic {
level: $lvl,
file: file!(),
line: line!(),
column: column!(),
function: "",
module: module_path!(),
target: module_path!(),
};
$l.log(&$crate::Record::new(&RS, format_args!("{}", $msg), &[$(($k, &$v)),*]))
}
};
($lvl:expr, $l:expr, $msg:expr; $($k:expr => $v:expr),*,) => {
slog_log!($lvl, $l, $msg; $($k => $v),*)
};
);
#[macro_export]
macro_rules! crit(
($($args:tt)+) => {
log!($crate::Level::Critical, $($args)+)
};
);
#[macro_export]
macro_rules! slog_crit(
($($args:tt)+) => {
slog_log!($crate::Level::Critical, $($args)+)
};
);
#[macro_export]
macro_rules! error(
($($args:tt)+) => {
log!($crate::Level::Error, $($args)+)
};
);
#[macro_export]
macro_rules! slog_error(
($($args:tt)+) => {
slog_log!($crate::Level::Error, $($args)+)
};
);
#[macro_export]
macro_rules! warn(
($($args:tt)+) => {
log!($crate::Level::Warning, $($args)+)
};
);
#[macro_export]
macro_rules! slog_warn(
($($args:tt)+) => {
slog_log!($crate::Level::Warning, $($args)+)
};
);
#[macro_export]
macro_rules! info(
($($args:tt)+) => {
log!($crate::Level::Info, $($args)+)
};
);
#[macro_export]
macro_rules! slog_info(
($($args:tt)+) => {
slog_log!($crate::Level::Info, $($args)+)
};
);
#[macro_export]
macro_rules! debug(
($($args:tt)+) => {
log!($crate::Level::Debug, $($args)+)
};
);
#[macro_export]
macro_rules! slog_debug(
($($args:tt)+) => {
slog_log!($crate::Level::Debug, $($args)+)
};
);
#[macro_export]
macro_rules! trace(
($($args:tt)+) => {
log!($crate::Level::Trace, $($args)+)
};
);
#[macro_export]
macro_rules! slog_trace(
($($args:tt)+) => {
slog_log!($crate::Level::Trace, $($args)+)
};
);
pub mod ser;
pub use ser::{PushLazy, ValueSerializer, Serializer, Serialize};
include!("_level.rs");
include!("_logger.rs");
include!("_drain.rs");
pub type BorrowedKeyValue<'a> = (&'static str, &'a ser::Serialize);
pub type OwnedKeyValue = (&'static str, Box<ser::SyncSerialize>);
pub struct OwnedKeyValueList {
parent: Option<Arc<OwnedKeyValueList>>,
values: Vec<OwnedKeyValue>,
}
impl OwnedKeyValueList {
pub fn new(values: Vec<OwnedKeyValue>, parent: Arc<OwnedKeyValueList>) -> Self {
OwnedKeyValueList {
parent: Some(parent),
values: values,
}
}
pub fn root(values: Vec<OwnedKeyValue>) -> Self {
OwnedKeyValueList {
parent: None,
values: values,
}
}
pub fn parent(&self) -> &Option<Arc<OwnedKeyValueList>> {
&self.parent
}
pub fn values(&self) -> &Vec<OwnedKeyValue> {
&self.values
}
pub fn iter(&self) -> OwnedKeyValueListIterator {
OwnedKeyValueListIterator::new(self)
}
}
pub struct OwnedKeyValueListIterator<'a> {
next_node: &'a Option<Arc<OwnedKeyValueList>>,
iter: slice::Iter<'a, OwnedKeyValue>,
}
impl<'a> OwnedKeyValueListIterator<'a> {
fn new(node: &'a OwnedKeyValueList) -> Self {
OwnedKeyValueListIterator {
next_node: &node.parent,
iter: node.values.iter(),
}
}
}
impl<'a> Iterator for OwnedKeyValueListIterator<'a> {
type Item = &'a OwnedKeyValue;
fn next(&mut self) -> Option<Self::Item> {
loop {
match self.iter.next() {
Some(x) => return Some(&*x),
None => {
match *self.next_node {
Some(ref node) => {
self.iter = node.values.iter();
self.next_node = &node.parent;
}
None => return None,
}
}
}
}
}
}
#[allow(unknown_lints)]
#[allow(inline_always)]
#[inline(always)]
#[doc(hidden)]
pub fn __slog_static_max_level() -> FilterLevel {
if !cfg!(debug_assertions) {
if cfg!(feature = "release_max_level_off") {
return FilterLevel::Off;
} else if cfg!(feature = "release_max_level_error") {
return FilterLevel::Error;
} else if cfg!(feature = "release_max_level_warn") {
return FilterLevel::Warning;
} else if cfg!(feature = "release_max_level_info") {
return FilterLevel::Info;
} else if cfg!(feature = "release_max_level_debug") {
return FilterLevel::Debug;
} else if cfg!(feature = "release_max_level_trace") {
return FilterLevel::Trace;
}
}
if cfg!(feature = "max_level_off") {
FilterLevel::Off
} else if cfg!(feature = "max_level_error") {
FilterLevel::Error
} else if cfg!(feature = "max_level_warn") {
FilterLevel::Warning
} else if cfg!(feature = "max_level_info") {
FilterLevel::Info
} else if cfg!(feature = "max_level_debug") {
FilterLevel::Debug
} else if cfg!(feature = "max_level_trace") {
FilterLevel::Trace
} else {
if !cfg!(debug_assertions) {
FilterLevel::Info
} else {
FilterLevel::Debug
}
}
}
#[cfg(test)]
mod tests;