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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
extern crate clap;
extern crate exar;
extern crate exar_server;
extern crate rustc_serialize;
extern crate toml_config;
#[macro_use]
extern crate log;
extern crate log4rs;
mod config;
use config::*;
use clap::App;
use exar::*;
use exar_server::*;
use log::LogLevelFilter;
use log4rs::append::console::ConsoleAppender;
use log4rs::config::{Appender, Config as Log4rsConfig, Root};
use std::path::Path;
use toml_config::ConfigFactory;
fn main() {
let matches = App::new("exar-db")
.version("0.1.0")
.author("Bruno Filippone <bruno.filippone@b-fil.com>")
.about("An event store with streaming support which uses a flat-file for each collection of events")
.args_from_usage(
"-c, --config=[FILE] 'Sets a custom config file'")
.get_matches();
let config = match matches.value_of("config") {
Some(config_file) => ConfigFactory::load(Path::new(config_file)),
None => Config::default()
};
match log4rs::init_file(config.log4rs_path.clone(), Default::default()) {
Ok(_) => info!("Loaded log4rs config file: {}", config.log4rs_path),
Err(_) => {
let console_appender = Appender::builder()
.build("console".to_owned(), Box::new(ConsoleAppender::builder().build()));
let root = Root::builder()
.appender("console".to_owned())
.build(LogLevelFilter::Info);
let log4rs_config = Log4rsConfig::builder()
.appender(console_appender)
.build(root).expect("Unable to build log4rs config");
log4rs::init_config(log4rs_config).expect("Unable to initialize log4rs config");
info!("Unable to load config file '{}', using default console appender", config.log4rs_path);
}
};
let db = Database::new(config.database);
match Server::new(config.server.clone(), db) {
Ok(server) => {
info!("ExarDB running at {}", config.server.address());
server.listen();
info!("ExarDB shutting down");
},
Err(err) => error!("Unable to run ExarDB: {}", err)
}
}