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
//! Krossbar logging library
//!
//! The library is used to connect to Krossbar logging service to send log messages
//! and receive log control commands.
//!
//! See [Krossbar log control](https://crates.io/crates/krossbar-log-control) documentation
//! on how to control logging.
//!
//! The library uses Unix stream connection to send logging messages, which means you need
//! running [Krossbar logger](https://crates.io/crates/krossbar-logger) to log mesage.
//! In case service can't connect to the logger, it logs to stdout.
//!
//! Also, you can use [Logger] manually to control whether log into stdout or send
//! message to the logger. Both option are independent.
//!
//! In case you use Krossbar logger, you have to run logging loop using [Logger::run].
//!
//! # Examples
//! ```rust
//! use std::time::Duration;
//!
//! use log::*;
//! use tokio::select;
//!
//! use krossbar_log_lib::init_logger;
//!
//! async fn log_example() {
//! let logger = init_logger("com.examples.logging", LevelFilter::Trace, true).await;
//!
//! tokio::spawn(logger.run());
//!
//! loop {
//! error!("Error message");
//! warn!("Warning message");
//! info!("Info message");
//! debug!("Debug message");
//! trace!("Trace message");
//!
//! select! {
//! _ = tokio::time::sleep(Duration::from_secs(1)) => {},
//! _ = tokio::signal::ctrl_c() => { return; }
//! }
//! }
//! }
//! ```
use LevelFilter;
use DEFAULT_LOGGER_SOCKET_PATH;
pub use Logger;
/// Init logger.
/// **service_name** is a client service name. It must be uniques across the system.
/// **log_to_stdout** sets if logger should log to stdout. If set, library
/// logs to stdout even if it then sends messages to the logger.
pub async