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] [package]
authors = ["Richard Newman <rnewman@twinql.com>", "Nicholas Alexander <nalexander@mozilla.com>"]
name = "mentat" name = "mentat"
version = "0.4.0" version = "0.4.0"
authors = ["Richard Newman <rnewman@twinql.com>", "Nicholas Alexander <nalexander@mozilla.com>"]
[dependencies] [dependencies]
clap = "2.19.3" clap = "2.19.3"
nickel = "0.9.0" nickel = "0.9.0"
slog = "1.4.0"
slog-scope = "0.2.2"
slog-term = "1.3.4"
[dependencies.rusqlite] [dependencies.rusqlite]
version = "0.9.3" version = "0.9.3"
@ -13,16 +16,16 @@ version = "0.9.3"
features = ["bundled"] features = ["bundled"]
[dependencies.edn] [dependencies.edn]
path = "edn" path = "edn"
[dependencies.mentat_db] [dependencies.mentat_db]
path = "db" path = "db"
[dependencies.mentat_query] [dependencies.mentat_query]
path = "query" path = "query"
[dependencies.mentat_query_parser] [dependencies.mentat_query_parser]
path = "query-parser" path = "query-parser"
[dependencies.mentat_tx_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 // CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License. // 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 edn;
extern crate mentat_query; extern crate mentat_query;
extern crate mentat_query_parser; extern crate mentat_query_parser;
@ -18,6 +23,7 @@ use rusqlite::Connection;
pub mod ident; pub mod ident;
pub fn get_name() -> String { pub fn get_name() -> String {
info!("Called into mentat library"; "fn" => "get_name");
return String::from("mentat"); return String::from("mentat");
} }

View file

@ -13,7 +13,16 @@ extern crate clap;
use nickel::{Nickel, HttpRouter}; 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 clap::{App, Arg, SubCommand, AppSettings};
use slog::DrainExt;
use std::u16; use std::u16;
use std::str::FromStr; use std::str::FromStr;
@ -44,10 +53,29 @@ fn main() {
let debug = matches.is_present("debug"); let debug = matches.is_present("debug");
let port = u16::from_str(matches.value_of("port").unwrap()).expect("Port must be an integer"); let port = u16::from_str(matches.value_of("port").unwrap()).expect("Port must be an integer");
if debug { if debug {
println!("This doesn't do anything yet, but it will eventually serve up the following database: {}", println!("This doesn't do anything yet, but it will eventually serve up the following database: {} \
matches.value_of("database").unwrap()); 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(); let mut server = Nickel::new();
server.get("/", middleware!("This doesn't do anything yet")); server.get("/", middleware!("This doesn't do anything yet"));
server.listen(("127.0.0.1", port)).expect("Failed to launch server"); server.listen(("127.0.0.1", port)).expect("Failed to launch server");