pub mod black_hole;
pub mod file;
pub mod io;
#[cfg(unix)]
pub mod journald;
pub mod log_file;
pub mod memory;
pub mod stderr;
pub mod stdout;
pub mod syslog;
use ntime;
use std::io as std_io;
use crate::attributes;
use crate::level;
pub type LogDepth = u16;
#[derive(Clone, Debug)]
pub struct PartialLogUpdate {
pub when: ntime::Timestamp,
pub level: level::Level,
pub depth: LogDepth,
pub msg: String,
}
impl PartialLogUpdate {
pub fn blank() -> Self {
Self {
when: ntime::Timestamp::epoch(),
level: level::Level::Panic,
depth: 0,
msg: String::from(""),
}
}
pub fn new(now: ntime::Timestamp, level: level::Level, depth: LogDepth, msg: String) -> Self {
Self {
when: now,
level: level,
depth: depth,
msg: msg,
}
}
pub fn copy_from(&mut self, other: &Self) {
self.when.copy_from(&other.when);
self.level = other.level;
self.msg.clear();
self.msg.insert_str(0, other.msg.as_str());
}
pub fn set_when(&mut self, when: ntime::Timestamp) {
self.when = when;
}
pub fn set_level(&mut self, level: level::Level) {
self.level = level;
}
pub fn set_depth(&mut self, depth: LogDepth) {
self.depth = depth;
}
pub fn set_msg(&mut self, msg: &str) {
self.msg.clear();
self.msg.insert_str(0, msg);
}
}
#[derive(Clone, Debug)]
pub struct LogUpdate<'s> {
partial: &'s PartialLogUpdate,
attrs: &'s attributes::Map,
}
impl<'i> From<(&'i PartialLogUpdate, &'i attributes::Map)> for LogUpdate<'i> {
fn from((partial, attrs): (&'i PartialLogUpdate, &'i attributes::Map)) -> Self {
Self { partial: partial, attrs: attrs }
}
}
impl<'i> LogUpdate<'i> {
pub fn parts(&self) -> (&'i PartialLogUpdate, &'i attributes::Map) {
(self.partial, self.attrs)
}
pub fn when(&self) -> &'i ntime::Timestamp {
&self.partial.when
}
pub fn level(&self) -> &'i level::Level {
&self.partial.level
}
pub fn depth(&self) -> &'i LogDepth {
&self.partial.depth
}
pub fn message(&self) -> &'i str {
self.partial.msg.as_str()
}
pub fn attributes(&self) -> &'i attributes::Map {
self.attrs
}
}
pub trait Sink {
fn name(&self) -> &str;
fn log<'f>(&mut self, update: &'f LogUpdate) -> std_io::Result<()>;
fn flush(&mut self) -> std_io::Result<()>;
}