-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_eval.rs
57 lines (46 loc) · 1.72 KB
/
print_eval.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use configcat::*;
use log::kv::Key;
use log::{Level, LevelFilter, Log, Metadata, Record};
use std::time::Duration;
#[tokio::main]
async fn main() {
// Info level logging helps to inspect the feature flag evaluation process.
// Use the default Warning level to avoid too detailed logging in your application.
log::set_max_level(LevelFilter::Info);
log::set_logger(&PrintLog {}).unwrap();
let client = Client::builder("PKDVCLf-Hq-h-kCzMp-L7Q/HhOWfwVtZ0mb30i9wi17GQ")
.polling_mode(PollingMode::AutoPoll(Duration::from_secs(5)))
.build()
.unwrap();
let is_awesome_enabled = client
.get_value("isAwesomeFeatureEnabled", false, None)
.await;
println!("isAwesomeFeatureEnabled: {is_awesome_enabled}");
let user = User::new("#SOME-USER-ID#").email("[email protected]");
let is_poc_enabled = client
.get_value("isPOCFeatureEnabled", false, Some(user))
.await;
println!("isPOCFeatureEnabled: {is_poc_enabled}");
}
// Example log implementation.
pub struct PrintLog {}
impl Log for PrintLog {
fn enabled(&self, metadata: &Metadata) -> bool {
metadata.level() <= log::max_level() && metadata.target().contains("configcat")
}
fn log(&self, record: &Record) {
if !self.enabled(record.metadata()) {
return;
}
let level = match record.level() {
Level::Error => "ERROR",
Level::Warn => "WARN",
Level::Info => "INFO",
Level::Debug => "DEBUG",
Level::Trace => "TRACE",
};
let event_id = record.key_values().get(Key::from("event_id")).unwrap();
println!("{level} [{event_id}] {}", record.args());
}
fn flush(&self) {}
}