chore: rename functions and fix wrong logs

This commit is contained in:
João Marcos P. Bezerra 2024-11-18 00:27:22 -03:00 committed by João Marcos
parent cc530bea94
commit 3e890eb307

View File

@ -14,7 +14,7 @@ pub fn shutdown_logger_and_wait() {
/// Asks logger to flush all messages, useful before starting STDIN interaction. /// Asks logger to flush all messages, useful before starting STDIN interaction.
#[track_caller] #[track_caller]
pub fn flush_messages() { pub fn flush_messages() {
logger_thread::send_flush_message_and_wait(); logger_thread::send_flush_command_and_wait();
} }
/// An `[INFO]` log to be displayed if we're not running accessibility mode. /// An `[INFO]` log to be displayed if we're not running accessibility mode.
@ -42,7 +42,7 @@ pub fn info_accessible(contents: String) {
#[track_caller] #[track_caller]
fn info_with_accessibility(contents: String, accessible: bool) { fn info_with_accessibility(contents: String, accessible: bool) {
logger_thread::send_log_message(PrintMessage { logger_thread::send_print_command(PrintMessage {
contents, contents,
accessible, accessible,
level: MessageLevel::Info, level: MessageLevel::Info,
@ -51,7 +51,7 @@ fn info_with_accessibility(contents: String, accessible: bool) {
#[track_caller] #[track_caller]
pub fn warning(contents: String) { pub fn warning(contents: String) {
logger_thread::send_log_message(PrintMessage { logger_thread::send_print_command(PrintMessage {
contents, contents,
// Warnings are important and unlikely to flood, so they should be displayed // Warnings are important and unlikely to flood, so they should be displayed
accessible: true, accessible: true,
@ -76,7 +76,7 @@ struct PrintMessage {
} }
impl PrintMessage { impl PrintMessage {
fn to_processed_message(&self) -> Option<String> { fn to_formatted_message(&self) -> Option<String> {
match self.level { match self.level {
MessageLevel::Info => { MessageLevel::Info => {
if self.accessible { if self.accessible {
@ -134,21 +134,21 @@ mod logger_thread {
} }
#[track_caller] #[track_caller]
pub(super) fn send_log_message(msg: PrintMessage) { pub(super) fn send_print_command(msg: PrintMessage) {
get_sender() get_sender()
.send(LoggerCommand::Print(msg)) .send(LoggerCommand::Print(msg))
.expect("Failed to send print message"); .expect("Failed to send print command");
} }
#[track_caller] #[track_caller]
pub(super) fn send_flush_message_and_wait() { pub(super) fn send_flush_command_and_wait() {
let barrier = Arc::new(Barrier::new(2)); let barrier = Arc::new(Barrier::new(2));
get_sender() get_sender()
.send(LoggerCommand::Flush { .send(LoggerCommand::Flush {
finished_barrier: barrier.clone(), finished_barrier: barrier.clone(),
}) })
.expect("Failed to send shutdown message"); .expect("Failed to send flush command");
barrier.wait(); barrier.wait();
} }
@ -161,7 +161,7 @@ mod logger_thread {
.send(LoggerCommand::FlushAndShutdown { .send(LoggerCommand::FlushAndShutdown {
finished_barrier: barrier.clone(), finished_barrier: barrier.clone(),
}) })
.expect("Failed to send shutdown message"); .expect("Failed to send shutdown command");
barrier.wait(); barrier.wait();
} }
@ -189,7 +189,7 @@ mod logger_thread {
match msg { match msg {
LoggerCommand::Print(msg) => { LoggerCommand::Print(msg) => {
// Append message to buffer // Append message to buffer
if let Some(msg) = msg.to_processed_message() { if let Some(msg) = msg.to_formatted_message() {
buffer.push(msg); buffer.push(msg);
} }