move LoggerSink to util.rs
parent
01a737285c
commit
36e3c4a145
|
@ -1,6 +1,7 @@
|
||||||
use crate::addressing::Address;
|
use crate::addressing::Address;
|
||||||
use crate::hash::{decode, hash, Hash, Hashable};
|
use crate::hash::{decode, hash, Hash, Hashable};
|
||||||
use crate::models;
|
use crate::models;
|
||||||
|
use crate::util::LoggerSink;
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use actix_derive::Message;
|
use actix_derive::Message;
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
@ -339,36 +340,6 @@ impl diesel::r2d2::CustomizeConnection<SqliteConnection, diesel::r2d2::Error>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct LoggerSink {
|
|
||||||
buffer: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::io::Write for LoggerSink {
|
|
||||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
|
||||||
self.buffer.extend(buf.iter());
|
|
||||||
|
|
||||||
if self.buffer.ends_with(b"\n") {
|
|
||||||
self.flush()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(buf.len())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn flush(&mut self) -> std::io::Result<()> {
|
|
||||||
use std::str;
|
|
||||||
|
|
||||||
debug!(
|
|
||||||
"{}",
|
|
||||||
str::from_utf8(self.buffer.as_mut())
|
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?
|
|
||||||
.trim()
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct OpenResult {
|
pub struct OpenResult {
|
||||||
pub pool: DbPool,
|
pub pool: DbPool,
|
||||||
pub new: bool,
|
pub new: bool,
|
||||||
|
|
|
@ -19,6 +19,7 @@ mod hash;
|
||||||
mod models;
|
mod models;
|
||||||
mod routes;
|
mod routes;
|
||||||
mod schema;
|
mod schema;
|
||||||
|
mod util;
|
||||||
|
|
||||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct LoggerSink {
|
||||||
|
buffer: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::io::Write for LoggerSink {
|
||||||
|
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
||||||
|
self.buffer.extend(buf.iter());
|
||||||
|
|
||||||
|
if self.buffer.ends_with(b"\n") {
|
||||||
|
self.flush()?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(buf.len())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flush(&mut self) -> std::io::Result<()> {
|
||||||
|
use std::str;
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"{}",
|
||||||
|
str::from_utf8(self.buffer.as_mut())
|
||||||
|
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?
|
||||||
|
.trim()
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue