Skip to content

Commit

Permalink
remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Jul 27, 2024
1 parent 01f1157 commit a560919
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/fast_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Logger {
now: SystemTime::now(),
formated: log,
};
if let Some(send) = LOGGER.get_or_init(|| { Logger::default() }).send.get() {
if let Some(send) = logger().send.get() {
send.send(fast_log_record)
} else {
// Ok(())
Expand All @@ -67,8 +67,8 @@ impl Log for Logger {
metadata.level() <= self.get_level()
}
fn log(&self, record: &Record) {
if let Some(filter) = LOGGER.get_or_init(|| { Logger::default() }).cfg.get() {
if let Some(send) = LOGGER.get_or_init(|| { Logger::default() }).send.get() {
if let Some(filter) = logger().cfg.get() {
if let Some(send) = logger().send.get() {
for filter in filter.filters.iter() {
if !filter.do_log(record) {
return;
Expand Down Expand Up @@ -103,21 +103,21 @@ pub fn init(config: Config) -> Result<&'static Logger, LogError> {
return Err(LogError::from("[fast_log] appends can not be empty!"));
}
let (s, r) = chan(config.chan_len);
LOGGER.get_or_init(|| { Logger::default() }).send.set(s).map_err(|_| LogError::from("set fail"))?;
LOGGER.get_or_init(|| { Logger::default() }).recv.set(r).map_err(|_| LogError::from("set fail"))?;
LOGGER.get_or_init(|| { Logger::default() }).set_level(config.level);
LOGGER.get_or_init(|| { Logger::default() })
logger().send.set(s).map_err(|_| LogError::from("set fail"))?;
logger().recv.set(r).map_err(|_| LogError::from("set fail"))?;
logger().set_level(config.level);
logger()
.cfg
.set(config)
.map_err(|_| LogError::from("set fail="))?;
//main recv data
log::set_logger(LOGGER.get_or_init(|| { Logger::default() }))
.map(|()| log::set_max_level(LOGGER.get_or_init(|| { Logger::default() }).cfg.get().unwrap().level))
log::set_logger(logger())
.map(|()| log::set_max_level(logger().cfg.get().unwrap().level))
.map_err(|e| LogError::from(e))?;

let mut receiver_vec = vec![];
let mut sender_vec: Vec<Sender<Arc<Vec<FastLogRecord>>>> = vec![];
let cfg = LOGGER.get_or_init(|| { Logger::default() }).cfg.get().unwrap();
let cfg = logger().cfg.get().unwrap();
for a in cfg.appends.iter() {
let (s, r) = chan(cfg.chan_len);
sender_vec.push(s);
Expand Down Expand Up @@ -172,7 +172,7 @@ pub fn init(config: Config) -> Result<&'static Logger, LogError> {
let senders = sender_vec.clone();
spawn(move || {
loop {
let recv = LOGGER.get_or_init(|| { Logger::default() }).recv.get().unwrap();
let recv = logger().recv.get().unwrap();
let mut remain = Vec::with_capacity(recv.len());
//recv
if recv.len() == 0 {
Expand All @@ -194,7 +194,7 @@ pub fn init(config: Config) -> Result<&'static Logger, LogError> {
let mut exit = false;
for x in &mut remain {
if x.formated.is_empty() {
LOGGER.get_or_init(|| { Logger::default() }).cfg.get().unwrap().format.do_format(x);
logger().cfg.get().unwrap().format.do_format(x);
}
if x.command.eq(&Command::CommandExit) {
exit = true;
Expand All @@ -210,7 +210,7 @@ pub fn init(config: Config) -> Result<&'static Logger, LogError> {
}
});
}
return Ok(LOGGER.get_or_init(|| { Logger::default() }));
return Ok(logger());
}

pub fn exit() -> Result<(), LogError> {
Expand All @@ -225,7 +225,7 @@ pub fn exit() -> Result<(), LogError> {
now: SystemTime::now(),
formated: String::new(),
};
let result = LOGGER.get_or_init(|| { Logger::default() })
let result = logger()
.send
.get()
.ok_or_else(|| LogError::from("not init"))?
Expand All @@ -252,7 +252,7 @@ pub fn flush() -> Result<WaitGroup, LogError> {
now: SystemTime::now(),
formated: String::new(),
};
let result = LOGGER.get_or_init(|| { Logger::default() })
let result = logger()
.send
.get()
.ok_or_else(|| LogError::from("not init"))?
Expand All @@ -267,5 +267,5 @@ pub fn flush() -> Result<WaitGroup, LogError> {
}

pub fn print(log: String) -> Result<(), SendError<FastLogRecord>> {
LOGGER.get_or_init(|| { Logger::default() }).print(log)
logger().print(log)
}

0 comments on commit a560919

Please sign in to comment.