aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/writer.rs')
-rw-r--r--src/writer.rs42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/writer.rs b/src/writer.rs
index e82d674..7ed1775 100644
--- a/src/writer.rs
+++ b/src/writer.rs
@@ -2,12 +2,14 @@ use std::collections::HashSet;
use async_recursion::async_recursion;
use tokio::io::{AsyncWrite, AsyncWriteExt};
+use tracing::info;
use crate::{
declaration::{Declaration, VersionInfo},
element::{escape_str, Content, Element, IntoContent, IntoElement, Name, NamespaceDeclaration},
endable::Endable,
error::Error,
+ loggable::Loggable,
xml::{self, composers::Composer, parsers_complete::Parser},
Result, XMLNS_NS, XML_NS,
};
@@ -15,7 +17,7 @@ use crate::{
// pub struct Writer<W, C = Composer> {
#[derive(Debug)]
pub struct Writer<W> {
- inner: Endable<W>,
+ inner: Endable<Loggable<W>>,
depth: Vec<Name>,
namespace_declarations: Vec<HashSet<NamespaceDeclaration>>,
}
@@ -32,14 +34,14 @@ impl<W> Writer<W> {
namespace: XMLNS_NS.to_string(),
});
Self {
- inner: Endable::new(writer),
+ inner: Endable::new(Loggable::new(writer)),
depth: Vec::new(),
namespace_declarations: vec![default_declarations],
}
}
pub fn into_inner(self) -> W {
- self.inner.into_inner()
+ self.inner.into_inner().into_inner()
}
}
@@ -65,24 +67,48 @@ impl<W: AsyncWrite + Unpin + Send> Writer<W> {
pub async fn write_full(&mut self, into_element: &impl IntoElement) -> Result<()> {
let element = into_element.into_element();
- Ok(self.write_element(&element).await?)
+ self.write_element(&element).await?;
+ let bytes = &self.inner.ignore_end().take_log();
+ let log = str::from_utf8(bytes).unwrap_or("failed to convert bytes written to str");
+ info!("wrote element: {}", log);
+ Ok(())
}
pub async fn write_start(&mut self, into_element: &impl IntoElement) -> Result<()> {
let element = into_element.into_element();
- Ok(self.write_element_start(&element).await?)
+ self.write_element_start(&element).await?;
+ let bytes = &self.inner.ignore_end().take_log();
+ let log = str::from_utf8(bytes).unwrap_or("failed to convert bytes written to str");
+ info!("wrote element start: {}", log);
+ Ok(())
}
pub async fn write_all_content(&mut self, into_element: &impl IntoElement) -> Result<()> {
for content in &into_element.get_content() {
self.write_content(content).await?;
}
+ let bytes = &self.inner.ignore_end().take_log();
+ let log = str::from_utf8(bytes).unwrap_or("failed to convert bytes written to str");
+ info!("wrote element content: {}", log);
Ok(())
}
pub async fn write(&mut self, into_content: &impl IntoContent) -> Result<()> {
let content = into_content.into_content();
- Ok(self.write_content(&content).await?)
+ self.write_content(&content).await?;
+ let bytes = &self.inner.ignore_end().take_log();
+ let log = str::from_utf8(bytes).unwrap_or("failed to convert bytes written to str");
+ info!("wrote element: {}", log);
+ Ok(())
+ }
+
+ // pub async fn write_end(&mut self)
+ pub async fn write_end(&mut self) -> Result<()> {
+ self.write_end_tag().await?;
+ let bytes = &self.inner.ignore_end().take_log();
+ let log = str::from_utf8(bytes).unwrap_or("failed to convert bytes written to str");
+ info!("wrote element end: {}", log);
+ Ok(())
}
#[async_recursion]
@@ -94,7 +120,7 @@ impl<W: AsyncWrite + Unpin + Send> Writer<W> {
for content in &element.content {
self.write_content(content).await?;
}
- self.write_end().await?;
+ self.write_end_tag().await?;
}
Ok(())
}
@@ -334,7 +360,7 @@ impl<W: AsyncWrite + Unpin + Send> Writer<W> {
Ok(())
}
- pub async fn write_end(&mut self) -> Result<()> {
+ pub async fn write_end_tag(&mut self) -> Result<()> {
let writer = self.inner.try_as_mut()?;
if let Some(name) = &self.depth.pop() {
let e_tag;