Skip to content

Commit

Permalink
Update v0.0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
george012 committed May 10, 2024
1 parent fe11a8e commit 440ed4c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rs_box"
version = "0.0.14"
version = "0.0.15"
description = "rust develop box"
edition = "2021"
readme = "README.md"
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# rs_box

```
```ignore
cargo fix --lib -p rs_box --allow-dirty
cargo fix --lib -p rs_box --tests --allow-dirty
```


Expand Down
2 changes: 0 additions & 2 deletions src/rs_box_log/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
pub mod rs_box_log;
mod rs_box_log_tests;
pub mod rs_box_log_log4rs;

38 changes: 26 additions & 12 deletions src/rs_box_log/rs_box_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use slog_async::Async;
use std::fs::{File, OpenOptions};
use std::sync::{Mutex};
use lazy_static::lazy_static;
use crate::rs_box_log::rs_box_log;

Check warning on line 10 in src/rs_box_log/rs_box_log.rs

View workflow job for this annotation

GitHub Actions / Build

unused import: `crate::rs_box_log::rs_box_log`
lazy_static! {
static ref GLOBAL_LOG_CONFIG: Mutex<Option<LogConfig>> = Mutex::new(None);
static ref DEFAULT_LOGGER: Mutex<Option<LoggerManager>> = Mutex::new(None);
Expand Down Expand Up @@ -87,7 +88,7 @@ fn create_slog_logger_write_file(file: File) -> slog::Logger {
}

fn custom_timestamp(w: &mut dyn std::io::Write) -> std::io::Result<()> {
write!(w, "{}", chrono::prelude::Utc::now().format("utc_%Y-%m-%d_%H:%M:%S"))
write!(w, "{}", chrono::prelude::Utc::now().format("UTC %Y-%m-%d_%H:%M:%S"))
}
impl LoggerManager {

Expand Down Expand Up @@ -140,27 +141,40 @@ impl LoggerManager {
logger
}
}
pub fn log_format(&self, message: &str) {
self.logger.log()
slog::info!(self.logger, "{}", message);
}


fn log_format(&self, message: &str,a_log_level: LogLevel) {

match a_log_level{
LogLevel::LogLevelDebug => {
slog::debug!(self.logger, "{}", message);
}
LogLevel::LogLevelError => {
slog::error!(self.logger, "{}", message);
}
LogLevel::LogLevelWarning => {
slog::warn!(self.logger, "{}", message);
}
LogLevel::LogLevelInfo => {
slog::info!(self.logger, "{}", message);
}
LogLevel::LogLevelTrace => {
slog::trace!(self.logger, "{}", message);
}
}
}
pub fn log_info_f(&self, message: &str) {
slog::info!(self.logger, "{}", message);
self.log_format(message,self::LogLevel::LogLevelInfo);
}
pub fn log_warning_f(&self, message: &str) {
slog::warn!(self.logger, "{}", message);
self.log_format(message,self::LogLevel::LogLevelWarning);
}
pub fn log_error_f(&self, message: &str) {
slog::error!(self.logger, "{}", message);
self.log_format(message,self::LogLevel::LogLevelError);
}
pub fn log_debug_f(&self, message: &str) {
slog::debug!(self.logger, "{}", message);
self.log_format(message,self::LogLevel::LogLevelDebug);
}
pub fn log_trace_f(&self, message: &str) {
slog::trace!(self.logger, "{}", message);
self.log_format(message,self::LogLevel::LogLevelTrace);
}
}

Expand Down
Empty file.
10 changes: 5 additions & 5 deletions src/rs_box_log/rs_box_log_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ fn test_logs_with_write_logfile() {

// 创建 100 个线程
let mut handles = vec![];
for i in 0..10 {
for i in 0..100 {
let handle = std::thread::spawn(move || {
rs_box_log::log_info(format!("main log test at thread {}",i).as_str());
rs_box_log::log_info(format!("main log test at thread {}", i).as_str(), );

let a_sub_log_mg = rs_box_log::LoggerManager::new(format!("test_thread_{}",i).as_str());
a_sub_log_mg.log_info_f(format!("a sub write file warning {}",i).as_str());
Expand All @@ -33,7 +33,7 @@ fn test_logs_with_write_logfile() {
#[test]
fn test_logs_with_terminal_show() {
rs_box_log::setup_log_tools("test_terminal_show",false,"",rs_box_log::LogLevel::LogLevelDebug,7,rs_box_log::LogFileSaveType::LogFileSaveTypeDays);
rs_box_log::log_info("This is an info message");
rs_box_log::log_info("This is an info message", );
rs_box_log::log_error("This is an error message");
rs_box_log::log_warning("This is an warning message");
rs_box_log::log_debug("This is an debug message");
Expand All @@ -42,9 +42,9 @@ fn test_logs_with_terminal_show() {

// 创建 100 个线程
let mut handles = vec![];
for i in 0..1000 {
for i in 0..100 {
let handle = std::thread::spawn(move || {
rs_box_log::log_info(format!("main-show log test at thread {}",i).as_str());
rs_box_log::log_info(format!("main-show log test at thread {}", i).as_str(), );

let a_sub_log_mg = rs_box_log::LoggerManager::new(format!("sub_test_terminal_show_{}",i).as_str());
a_sub_log_mg.log_info_f("a sub write file info");
Expand Down

0 comments on commit 440ed4c

Please sign in to comment.