-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a basic logger helper for users to get started easily
- Loading branch information
Showing
8 changed files
with
85 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
pub mod copperlist; | ||
pub mod config; | ||
pub mod copperlist; | ||
pub mod curuntime; | ||
pub mod cutask; | ||
pub mod monitoring; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "copper-helpers" | ||
version = "0.1.0" | ||
authors = ["Guillaume Binet <[email protected]>"] | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
keywords = ["robotics", "middleware", "copper", "real-time"] | ||
categories = ["science::robotics"] | ||
|
||
[dependencies] | ||
copper-traits = { path = "../copper_traits" } | ||
copper-datalogger = { path = "../copper_datalogger" } | ||
copper-log = { path = "../copper_log" } | ||
copper-log-runtime = { path = "../copper_log_runtime" } | ||
copper-clock = { path = "../copper_clock" } | ||
simplelog = "0.12.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use copper_clock::RobotClock; | ||
use copper_datalogger::{stream_write, DataLogger, DataLoggerBuilder}; | ||
use copper_log::default_log_index_dir; | ||
use copper_log_runtime::{ExtraTextLogger, LoggerRuntime}; | ||
use copper_traits::{CuResult, DataLogType}; | ||
use simplelog::{ColorChoice, Config, LevelFilter, TermLogger, TerminalMode}; | ||
use std::path::Path; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
/// This is a basic setup for a copper application to get you started. | ||
/// Duplicate and customize as needed when your needs grow. | ||
/// | ||
/// text_log: if true, the log will be printed to the console as a simple log. | ||
/// It is useful to debug an application in real-time but should be set to false in production | ||
/// as it is an order of magnitude slower than the default copper structured logging. | ||
/// It will create a LoggerRuntime that can be used as a robot clock source too. | ||
pub fn basic_logger_runtime_setup( | ||
datalogger_output_path: &Path, | ||
text_log: bool, | ||
) -> CuResult<LoggerRuntime> { | ||
let DataLogger::Write(logger) = DataLoggerBuilder::new() | ||
.write(true) | ||
.create(true) | ||
.file_path(datalogger_output_path) | ||
.preallocated_size(100000) | ||
.build() | ||
.expect("Failed to create logger") | ||
else { | ||
panic!("Failed to create logger") | ||
}; | ||
let data_logger = Arc::new(Mutex::new(logger)); | ||
let stream = stream_write(data_logger.clone(), DataLogType::StructuredLogLine, 1024); | ||
|
||
let extra = if text_log { | ||
let slow_text_logger = TermLogger::new( | ||
LevelFilter::Debug, | ||
Config::default(), | ||
TerminalMode::Mixed, | ||
ColorChoice::Auto, | ||
); | ||
|
||
// This is the path to the index file that was created at build time. | ||
// depending if we build with debug pick it from debug or release: | ||
let log_index_path = default_log_index_dir(); | ||
|
||
let extra_text_logger: ExtraTextLogger = | ||
ExtraTextLogger::new(log_index_path, slow_text_logger); | ||
Some(extra_text_logger) | ||
} else { | ||
None | ||
}; | ||
Ok(LoggerRuntime::init(RobotClock::default(), stream, extra)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters