Improved logging
This commit is contained in:
@@ -166,8 +166,6 @@ impl StrategyEngine {
|
||||
.unwrap()
|
||||
.as_millis() as u64;
|
||||
|
||||
println!("getting candlestick");
|
||||
|
||||
let interval_ms = match interval {
|
||||
CandleInterval::OneMinute => 60_000,
|
||||
CandleInterval::ThreeMinutes => 3 * 60_000,
|
||||
|
||||
@@ -45,7 +45,11 @@ impl TerminalServer {
|
||||
|
||||
let listener = UnixListener::bind(&path)?;
|
||||
|
||||
println!("Terminal server listening on {:?}", path);
|
||||
self.info(
|
||||
"engine::terminal",
|
||||
&format!("Terminal server listening on {:?}", path),
|
||||
)
|
||||
.await?;
|
||||
|
||||
loop {
|
||||
let (stream, _) = listener.accept().await?;
|
||||
@@ -60,7 +64,13 @@ impl TerminalServer {
|
||||
|
||||
tokio::spawn(async move {
|
||||
if let Err(err) = s.handle_client(&id, reader).await {
|
||||
eprintln!("Terminal connection error: {err}");
|
||||
s.error(
|
||||
"engine::terminal",
|
||||
&format!("Terminal connection error: {err}"),
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -142,7 +152,12 @@ impl TerminalServer {
|
||||
for (id, client) in clients.iter_mut() {
|
||||
if let Err(e) = Self::send_to_client(client, &msg).await {
|
||||
remove_clients.push(*id);
|
||||
println!("{e:?}");
|
||||
|
||||
self.print_log(&EventLog {
|
||||
kind: LogKind::Err,
|
||||
name: "engine::terminal".to_string(),
|
||||
message: format!("Failed to broadcast to client: {e}"),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,19 +274,32 @@ impl TerminalServer {
|
||||
name: &str,
|
||||
message: &str,
|
||||
) -> tokio::io::Result<()> {
|
||||
let log = EventLog {
|
||||
self.log_raw(EventLog {
|
||||
kind,
|
||||
name: name.to_string(),
|
||||
message: message.to_string(),
|
||||
};
|
||||
|
||||
self.logs.lock().await.push(log.clone());
|
||||
|
||||
self.broadcast(pulse_sdk::terminal::TerminalServerMessage::AddLog(log))
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub fn print_log(self: &Arc<Self>, log: &EventLog) {
|
||||
println!(
|
||||
"[{}{}\x1b[0m] (\x1b[37m{}\x1b[0m) {}",
|
||||
match &log.kind {
|
||||
LogKind::Info => "\x1b[34m",
|
||||
LogKind::Debug => "\x1b[36m",
|
||||
LogKind::Err => "\x1b[31m",
|
||||
LogKind::Warn => "\x1b[33m",
|
||||
},
|
||||
log.kind,
|
||||
log.name,
|
||||
log.message
|
||||
);
|
||||
}
|
||||
|
||||
pub async fn log_raw(self: &Arc<Self>, log: EventLog) -> tokio::io::Result<()> {
|
||||
self.print_log(&log);
|
||||
|
||||
self.logs.lock().await.push(log.clone());
|
||||
|
||||
self.broadcast(pulse_sdk::terminal::TerminalServerMessage::AddLog(log))
|
||||
|
||||
Reference in New Issue
Block a user