Implement basic logging infrastructure. (#205) r=nalexander,victorporof

Signed-off-by: Paul Lange <palango@gmx.de>
This commit is contained in:
Nick Alexander 2017-01-26 10:43:48 -08:00 committed by GitHub
parent 81af295948
commit 506c83c160
3 changed files with 45 additions and 8 deletions

View file

@ -1,11 +1,14 @@
[package]
authors = ["Richard Newman <rnewman@twinql.com>", "Nicholas Alexander <nalexander@mozilla.com>"]
name = "mentat"
version = "0.4.0"
authors = ["Richard Newman <rnewman@twinql.com>", "Nicholas Alexander <nalexander@mozilla.com>"]
[dependencies]
clap = "2.19.3"
nickel = "0.9.0"
slog = "1.4.0"
slog-scope = "0.2.2"
slog-term = "1.3.4"
[dependencies.rusqlite]
version = "0.9.3"
@ -13,16 +16,16 @@ version = "0.9.3"
features = ["bundled"]
[dependencies.edn]
path = "edn"
path = "edn"
[dependencies.mentat_db]
path = "db"
path = "db"
[dependencies.mentat_query]
path = "query"
path = "query"
[dependencies.mentat_query_parser]
path = "query-parser"
path = "query-parser"
[dependencies.mentat_tx_parser]
path = "tx-parser"
path = "tx-parser"

View file

@ -8,6 +8,11 @@
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
#[macro_use]
extern crate slog;
#[macro_use]
extern crate slog_scope;
extern crate edn;
extern crate mentat_query;
extern crate mentat_query_parser;
@ -18,6 +23,7 @@ use rusqlite::Connection;
pub mod ident;
pub fn get_name() -> String {
info!("Called into mentat library"; "fn" => "get_name");
return String::from("mentat");
}

View file

@ -13,7 +13,16 @@ extern crate clap;
use nickel::{Nickel, HttpRouter};
#[macro_use]
extern crate slog;
#[macro_use]
extern crate slog_scope;
extern crate slog_term;
extern crate mentat;
use clap::{App, Arg, SubCommand, AppSettings};
use slog::DrainExt;
use std::u16;
use std::str::FromStr;
@ -44,10 +53,29 @@ fn main() {
let debug = matches.is_present("debug");
let port = u16::from_str(matches.value_of("port").unwrap()).expect("Port must be an integer");
if debug {
println!("This doesn't do anything yet, but it will eventually serve up the following database: {}",
matches.value_of("database").unwrap());
println!("This doesn't do anything yet, but it will eventually serve up the following database: {} \
on port: {}.",
matches.value_of("database").unwrap(),
matches.value_of("port").unwrap());
}
// Set up logging.
let log_level = if debug {
slog::Level::Debug
} else {
slog::Level::Warning
};
let term_logger = slog_term::streamer().build().fuse();
let log = slog::Logger::root(slog::LevelFilter::new(term_logger, log_level),
o!("version" => env!("CARGO_PKG_VERSION")));
slog_scope::set_global_logger(log);
info!("Serving database"; "database" => matches.value_of("database").unwrap(),
"port" => port,
"debug mode" => debug);
error!("Calling a function: {}", mentat::get_name());
let mut server = Nickel::new();
server.get("/", middleware!("This doesn't do anything yet"));
server.listen(("127.0.0.1", port)).expect("Failed to launch server");