Skip to content

Commit 93fb552

Browse files
committed
add config
1 parent 7afbebb commit 93fb552

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎src/config.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub struct Config {
3333
pub format: Box<dyn RecordFormat>,
3434
/// the channel length,default None(Unbounded channel)
3535
pub chan_len: Option<usize>,
36+
/// number of worker threads that receive and dispatch log records from the main channel to appenders
37+
pub worker_tasks: Option<usize>,
3638
}
3739

3840
impl Debug for Config {
@@ -53,6 +55,7 @@ impl Default for Config {
5355
filters: SyncVec::new(),
5456
format: Box::new(FastLogFormat::new()),
5557
chan_len: None,
58+
worker_tasks: Some(1),
5659
}
5760
}
5861
}
@@ -192,4 +195,10 @@ impl Config {
192195
self.chan_len = len;
193196
self
194197
}
198+
199+
/// set the number of worker threads, default is 1
200+
pub fn worker_tasks(mut self, num: Option<usize>) -> Self {
201+
self.worker_tasks = num;
202+
self
203+
}
195204
}

‎src/fast_log.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ pub fn init(config: Config) -> Result<&'static Logger, LogError> {
174174
});
175175
}
176176
let sender_vec = Arc::new(sender_vec);
177-
for _ in 0..1 {
177+
let thread_num = cfg.worker_tasks.unwrap_or(1);
178+
for _ in 0..thread_num {
178179
let senders = sender_vec.clone();
179180
spawn(move || {
180181
loop {

0 commit comments

Comments
 (0)