Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Information logger #166

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e1104a0
Initial fix and exploration
t-lohse Apr 27, 2023
511db7e
Merge branch 'Ecdar-SW5/main' of github.com:Ecdar/Reveaal into memory…
t-lohse May 6, 2023
8622a2d
Finalized fix
t-lohse May 6, 2023
75aa8c1
Merge branch 'main' of github.com:Ecdar/Reveaal into memory-hogging-fix
t-lohse May 18, 2023
9824297
Minor optimizations
t-lohse May 18, 2023
a730b85
Invariant update
t-lohse May 18, 2023
2621e4f
Removed and refactored some unused and unnecessary functions
t-lohse May 18, 2023
373bee0
Removed additional
t-lohse May 18, 2023
72834a6
Initial impl
t-lohse May 18, 2023
4ae4686
added server check
t-lohse May 18, 2023
f79038c
added server check and impl Display
t-lohse May 18, 2023
acebea0
added server check and impl Display
t-lohse May 18, 2023
95fda46
Fixed test error
t-lohse May 18, 2023
511e371
Updated and added test
t-lohse May 22, 2023
b374069
refactor of module
t-lohse May 22, 2023
37c8f12
Added into
t-lohse May 22, 2023
225a060
Removed commented code
t-lohse May 22, 2023
a611bca
Changed to use lazy_static
t-lohse May 22, 2023
a7a7cd8
Changed to use lazy_static
t-lohse May 22, 2023
9efa8d6
Merge branch 'main' into memory-hogging-fix
t-lohse May 22, 2023
71fe7ed
merge main
t-lohse May 22, 2023
06d46c0
Merge branch 'component-unused-functions' of github.com:Ecdar/Reveaal…
t-lohse May 22, 2023
7b88911
refactored removal of invariants
t-lohse May 25, 2023
f5d1eb6
Added macro tests
t-lohse May 26, 2023
2c648ff
Merged main
t-lohse May 30, 2023
56dff37
Merged main
t-lohse May 30, 2023
ec39f1c
Merged main
t-lohse May 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added server check and impl Display
t-lohse committed May 18, 2023
commit f79038cfb8f18c3bdf3b44f39d828def63a51e12
15 changes: 9 additions & 6 deletions src/ModelObjects/component.rs
Original file line number Diff line number Diff line change
@@ -160,10 +160,12 @@ impl Component {
.is_none()
});

/*
info!(
"Removed Clock '{name}' (index {index}) has been removed from component {}",
self.name
); // Should be changed in the future to be the information logger
);
*/

msg!("Clock Reduction", msg: "Removed Clock '{name}' (index {index}) has been removed from component {}",
self.name);
@@ -187,11 +189,12 @@ impl Component {
let old = *index;
*index = global_index;
// TODO: Maybe log the global clock name instead of index

info!(
"Replaced Clock '{name}' (index {old}) with {global_index} in component {}",
self.name
);
/*
info!(
"Replaced Clock '{name}' (index {old}) with {global_index} in component {}",
self.name
);
*/

msg!("Clock Reduction",
msg: "Replaced Clock '{name}' (index {old}) with {global_index} in component {}",
2 changes: 1 addition & 1 deletion src/ProtobufServer/ecdar_requests/send_query.rs
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ impl ConcreteEcdarBackend {
let result = query.execute();
Ok(QueryResponse {
query_id: query_request.query_id,
info: crate::logging::get_messages().unwrap_or_default(),
info: crate::logging::get_messages(),
result: Some(result.into()),
})
}
66 changes: 44 additions & 22 deletions src/logging.rs
Original file line number Diff line number Diff line change
@@ -5,25 +5,26 @@ use log::SetLoggerError;
use once_cell::sync::Lazy;
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::fmt::{Display, Formatter};
use std::io::Write;
use std::sync::Mutex;
use std::thread;
use std::thread::ThreadId;
//use std::time::Duration;

#[cfg(feature = "logging")]
/// Sets up the logging
pub fn setup_logger() -> Result<(), SetLoggerError> {
fn colored_level(level: log::Level) -> ColoredString {
match level {
log::Level::Error => level.to_string().red(),
log::Level::Warn => level.to_string().yellow(),
log::Level::Info => level.to_string().cyan(),
log::Level::Debug => level.to_string().blue(),
log::Level::Trace => level.to_string().magenta(),
}
fn colored_level(level: log::Level) -> ColoredString {
match level {
log::Level::Error => level.to_string().red(),
log::Level::Warn => level.to_string().yellow(),
log::Level::Info => level.to_string().cyan(),
log::Level::Debug => level.to_string().blue(),
log::Level::Trace => level.to_string().magenta(),
}
}

#[cfg(feature = "logging")]
/// Sets up the logging
pub fn setup_logger() -> Result<(), SetLoggerError> {
env_logger::Builder::from_env(env_logger::Env::default())
.format(|buf, record| {
writeln!(
@@ -45,13 +46,9 @@ macro_rules! msg { //TODO: Maybe format the information when not server
if $crate::is_server() {
$crate::logging::__set_info__($crate::logging::__as_information__($severity, $subject, $msg));
} else {
//println!("{:?}", $crate::logging::__as_information__($severity, $subject, $msg));
let lvl = match $severity {
0 => log::Level::Info,
1 => log::Level::Warn,
_ => unreachable!(),
};
log::log!(lvl, "{:?}", $crate::logging::__as_information__($severity, $subject, $msg));
//let lvl = $crate::logging::__severity__($severity);
//log::log!(lvl, "{}", $crate::logging::__as_information__($severity, $subject, $msg));
println!("{}", $crate::logging::__as_information__($severity, $subject, $msg));
}
});

@@ -65,6 +62,28 @@ macro_rules! msg { //TODO: Maybe format the information when not server
($($msg:tt)+) => (msg!(0, subject: "general", msg: format_args!($($msg)+).to_string()));
}

#[doc(hidden)]
pub fn __severity__(severity: i32) -> log::Level {
match severity {
0 => log::Level::Info,
1 => log::Level::Warn,
_ => unreachable!(),
}
}

impl Display for Information {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"[{} {}: {}] - {}",
Local::now().format("%H:%M:%S").to_string().cyan(),
colored_level(__severity__(self.serverity)),
self.subject,
self.message
)
}
}

#[doc(hidden)]
static __MESSAGES__: Lazy<Mutex<HashMap<ThreadId, Vec<Information>>>> = Lazy::new(Mutex::default);

@@ -89,11 +108,10 @@ pub fn __set_info__(info: Information) {

//static mut TEMP: i32 = 10;

/// Function to get information messages
///
/// Function to get information messages.
/// ### Info
/// Will always return `None` when Reveaal is run through the CLI, only use as server.
pub fn get_messages() -> Option<Vec<Information>> {
pub fn get_messages() -> Vec<Information> {
//println!("{:?}", thread::current().name());
/*
unsafe {
@@ -109,5 +127,9 @@ pub fn get_messages() -> Option<Vec<Information>> {
}
*/

__MESSAGES__.lock().unwrap().remove(&thread::current().id())
__MESSAGES__
.lock()
.unwrap()
.remove(&thread::current().id())
.unwrap_or_default()
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![allow(non_snake_case)]
use clap::{load_yaml, App};
use reveaal::logging::{get_messages, setup_logger};
use reveaal::logging::setup_logger;
use reveaal::System::query_failures::QueryResult;

use reveaal::ProtobufServer::services::query_request::Settings;
use reveaal::{
extract_system_rep, msg, parse_queries, set_server, start_grpc_server_with_tokio, xml_parser,
extract_system_rep, parse_queries, set_server, start_grpc_server_with_tokio, xml_parser,
ComponentLoader, JsonProjectLoader, ProjectLoader, Query, XmlProjectLoader,
};
use std::env;