Update logging implementation
This commit is contained in:
parent
d07b899811
commit
1ede9a1b03
|
@ -35,12 +35,10 @@ optional = true
|
|||
|
||||
[dependencies.tracing]
|
||||
version = "0.1"
|
||||
optional = true
|
||||
|
||||
[features]
|
||||
default = ["tls"]
|
||||
tls = ["async-native-tls"]
|
||||
debug = ["tracing"]
|
||||
toml_support = ["toml", "serde", "serde_derive"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
|
|
|
@ -187,8 +187,7 @@ impl Command {
|
|||
pub async fn command_from_str(s: &str) -> Self {
|
||||
let new = s.trim();
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
tracing::info!("{}", new);
|
||||
tracing::debug!("{}", new);
|
||||
|
||||
let parts: Vec<&str> = new.split_whitespace().collect();
|
||||
|
||||
|
|
34
src/lib.rs
34
src/lib.rs
|
@ -51,7 +51,7 @@ pub struct Client {
|
|||
}
|
||||
|
||||
/// Config for the IRC client
|
||||
#[derive(Clone, Default)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
#[cfg_attr(feature = "toml_support", derive(Deserialize))]
|
||||
pub struct Config {
|
||||
channels: Vec<String>,
|
||||
|
@ -151,8 +151,7 @@ impl Client {
|
|||
.await?;
|
||||
}
|
||||
commands::Command::OTHER(line) => {
|
||||
#[cfg(feature = "debug")]
|
||||
tracing::info!("{}", line);
|
||||
tracing::debug!("{}", line);
|
||||
if line.contains("001") {
|
||||
break;
|
||||
}
|
||||
|
@ -210,9 +209,6 @@ impl Client {
|
|||
/// Returns error if there are no new messages. This should not be taken as an actual error, because nothing went wrong.
|
||||
pub async fn read(&mut self) -> Result<commands::Command, NoNewLines> {
|
||||
if let Some(string) = self.read_string().await {
|
||||
#[cfg(feature = "debug")]
|
||||
tracing::info!("{:#?}", string);
|
||||
|
||||
let command = commands::Command::command_from_str(&string).await;
|
||||
|
||||
if let commands::Command::PONG(command) = command {
|
||||
|
@ -234,8 +230,7 @@ impl Client {
|
|||
Cow::Owned(new) as Cow<str>
|
||||
};
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
tracing::info!("{:?}", formatted);
|
||||
tracing::debug!("{:?}", formatted);
|
||||
|
||||
self.stream.write_all(formatted.as_bytes()).await?;
|
||||
|
||||
|
@ -626,6 +621,7 @@ impl Config {
|
|||
port: u16,
|
||||
username: &str,
|
||||
) -> Self {
|
||||
tracing::info!("New circe client config");
|
||||
// Conversion from &'static str to String
|
||||
let channels_config = channels
|
||||
.iter()
|
||||
|
@ -646,14 +642,17 @@ impl Config {
|
|||
nickname_config = Some(username.to_string());
|
||||
}
|
||||
|
||||
Self {
|
||||
let config = Self {
|
||||
channels: channels_config,
|
||||
host: host.into(),
|
||||
mode: mode_config,
|
||||
nickname: nickname_config,
|
||||
port,
|
||||
username: username.into(),
|
||||
}
|
||||
};
|
||||
|
||||
tracing::debug!("circe config: {:?}", config);
|
||||
config
|
||||
}
|
||||
|
||||
/// Allows for configuring circe at runtime
|
||||
|
@ -665,6 +664,7 @@ impl Config {
|
|||
port: u16,
|
||||
username: String,
|
||||
) -> Self {
|
||||
tracing::info!("New circe client config");
|
||||
let mode_config: Option<String>;
|
||||
if let Some(mode) = mode {
|
||||
mode_config = Some(mode.to_string());
|
||||
|
@ -679,14 +679,17 @@ impl Config {
|
|||
nickname_config = Some(username.to_string());
|
||||
}
|
||||
|
||||
Self {
|
||||
let config = Self {
|
||||
channels,
|
||||
host,
|
||||
mode: mode_config,
|
||||
nickname: nickname_config,
|
||||
port,
|
||||
username,
|
||||
}
|
||||
};
|
||||
|
||||
tracing::debug!("circe config: {:?}", config);
|
||||
config
|
||||
}
|
||||
|
||||
/// Create a config from a toml file
|
||||
|
@ -704,14 +707,17 @@ impl Config {
|
|||
#[cfg_attr(docsrs, doc(cfg(feature = "toml_support")))]
|
||||
#[cfg(feature = "toml_support")]
|
||||
pub fn from_toml<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
|
||||
tracing::info!("New circe client config");
|
||||
use std::io::Read;
|
||||
let mut file = File::open(&path)?;
|
||||
let mut data = String::new();
|
||||
file.read_to_string(&mut data)?;
|
||||
|
||||
toml::from_str(&data).map_err(|e| {
|
||||
let config = toml::from_str(&data).map_err(|e| {
|
||||
use tokio::io::ErrorKind;
|
||||
Error::new(ErrorKind::Other, format!("Invalid TOML: {}", e))
|
||||
})
|
||||
});
|
||||
tracing::debug!("circe config: {:?}", config);
|
||||
config
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue