Skip to main content

simple/
simple.rs

1/*
2Astrolog, a logging framework for Rust
3Copyright (C) 2019 Alessandro Pellizzari
4
5This library is free software; you can redistribute it and/or
6modify it under the terms of the GNU Lesser General Public
7License as published by the Free Software Foundation; either
8version 2.1 of the License, or (at your option) any later version.
9
10This library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public
16License along with this library; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18*/
19
20extern crate astrolog;
21
22use std::env;
23
24use serde_json::json;
25
26use astrolog::handler::console::ConsoleHandler;
27use astrolog::prelude::*;
28
29fn main() {
30	let logger = Logger::new().with_handler(ConsoleHandler::new().with_levels_range(Level::Info, Level::Emergency));
31
32	logger.info("With no context");
33
34	let logger = logger.with_global("OS", env::consts::OS);
35
36	logger.debug("A debug message"); // Will not be printed
37	logger.info("A simple info logging");
38
39	logger
40		.with("line", line!())
41		.with("file", file!())
42		.error("An error with some debug info");
43
44	logger
45		.with_multi(json!({
46			"line": line!(),
47			"file": file!(),
48		}))
49		.critical("This is dangerous!");
50
51	let logger = Logger::new()
52		.with_handler(ConsoleHandler::new()
53			.with_formatter(LineFormatter::new()
54				.with_date_format(DateFormat::Email)
55				.with_level_format(LevelFormat::LowerShort)
56			)
57		);
58
59	logger
60		.with("line", line!())
61		.with("file", file!())
62		.error("An error with custom formatting");
63
64}