Skip to content

Commit

Permalink
use hashset instead
Browse files Browse the repository at this point in the history
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
  • Loading branch information
Connor1996 committed Aug 1, 2019
1 parent 45a41cd commit ba2ea3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions components/test_util/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2018 TiKV Project Authors. Licensed under Apache-2.0.

use std::collections::HashSet;
use std::env;
use std::fmt;
use std::fs::File;
Expand Down Expand Up @@ -101,7 +102,8 @@ pub fn init_log_for_test() {
let drain = CaseTraceLogger { f: writer };

// Collects following targets.
let mut enabled_targets = vec!["raft".to_owned()];
let mut enabled_targets = HashSet::new();
enabled_targets.insert("raft".to_owned());
// Collects logs for components.
if let Some(components_modules) = option_env!("TIKV_LOG_TARGETS") {
enabled_targets.extend(components_modules.split(' ').map(ToOwned::to_owned));
Expand All @@ -112,7 +114,7 @@ pub fn init_log_for_test() {
}
let filtered = drain.filter(|record| {
let module = record.module().splitn(2, "::").nth(1).unwrap();
enabled_targets.iter().any(|target| target == module)
enabled_targets.contain(module)
});

// CaseTraceLogger relies on test's thread name, however slog_async has
Expand Down
8 changes: 5 additions & 3 deletions src/binutil/setup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018 TiKV Project Authors. Licensed under Apache-2.0.

use std::borrow::ToOwned;
use std::collections::HashSet;
use std::env;
use std::sync::atomic::{AtomicBool, Ordering};

Expand Down Expand Up @@ -35,7 +36,8 @@ pub fn initial_logger(config: &TiKvConfig) {
.expect("config.log_rotation_timespan is an invalid duration.");

// Collects following targets.
let mut enabled_targets = vec!["raft".to_owned()];
let mut enabled_targets = HashSet::new();
enabled_targets.insert("raft".to_owned());
// Collects logs for components.
if let Some(components_modules) = option_env!("TIKV_LOG_TARGETS") {
enabled_targets.extend(components_modules.split(' ').map(ToOwned::to_owned));
Expand All @@ -48,7 +50,7 @@ pub fn initial_logger(config: &TiKvConfig) {
let drainer = logger::term_drainer();
let filtered = drainer.filter(move |record| {
let module = record.module().splitn(2, "::").nth(0).unwrap();
enabled_targets.iter().any(|target| target == module)
enabled_targets.contains(module)
});
// use async drainer and init std log.
logger::init_log(filtered, config.log_level, true, true).unwrap_or_else(|e| {
Expand All @@ -66,7 +68,7 @@ pub fn initial_logger(config: &TiKvConfig) {

let filtered = drainer.filter(move |record| {
let module = record.module().splitn(2, "::").nth(0).unwrap();
enabled_targets.iter().any(|target| target == module)
enabled_targets.contains(module)
});
// use async drainer and init std log.
logger::init_log(filtered, config.log_level, true, true).unwrap_or_else(|e| {
Expand Down

0 comments on commit ba2ea3d

Please sign in to comment.