blob: 6b355e54a50e8d91623b229c8ffb8062b53152b2 [file] [log] [blame]
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
use crate::reporter::{CollectItem, Report};
#[derive(Default, Clone)]
pub struct PrintReporter {
use_stderr: bool,
}
impl PrintReporter {
#[inline]
pub fn new() -> Self {
Default::default()
}
pub fn use_stderr(mut self, use_stderr: bool) -> Self {
self.use_stderr = use_stderr;
self
}
}
impl Report for PrintReporter {
fn report(&self, items: CollectItem) {
match items {
CollectItem::Trace(segment) => {
if self.use_stderr {
eprintln!("trace segment={:?}", segment);
} else {
println!("trace segment={:?}", segment);
}
}
CollectItem::Log(data) => {
if self.use_stderr {
eprintln!("log data={:?}", data);
} else {
println!("log data={:?}", data);
}
}
}
}
}