Skip to content

Commit

Permalink
update to 2018 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Sep 23, 2019
1 parent 7105e63 commit 8209524
Show file tree
Hide file tree
Showing 28 changed files with 478 additions and 496 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "env_logger"
edition = "2018"
version = "0.6.2" # remember to update html_root_url
authors = ["The Rust Project Developers"]
license = "MIT/Apache-2.0"
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ env_logger = "0.6.2"
```rust
#[macro_use]
extern crate log;
extern crate env_logger;

fn main() {
env_logger::init();
Expand Down Expand Up @@ -69,7 +68,6 @@ fn add_one(num: i32) -> i32 {
#[cfg(test)]
mod tests {
use super::*;
extern crate env_logger;

fn init() {
let _ = env_logger::builder().is_test(true).try_init();
Expand Down
1 change: 1 addition & 0 deletions ci/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "ci"
edition = "2018"
version = "0.0.0"
authors = ["The Rust Project Developers"]
publish = false
Expand Down
14 changes: 5 additions & 9 deletions ci/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
mod task;
mod permute;
mod task;

fn main() {
let features = [
"termcolor",
"humantime",
"atty",
"regex",
];
let features = ["termcolor", "humantime", "atty", "regex"];

// Run a default build
if !task::test(Default::default()) {
Expand All @@ -25,12 +20,13 @@ fn main() {
// Run a set of permutations
let failed = permute::all(&features)
.into_iter()
.filter(|features|
.filter(|features| {
!task::test(task::TestArgs {
features: features.clone(),
default_features: false,
lib_only: true,
}))
})
})
.collect::<Vec<_>>();

if failed.len() > 0 {
Expand Down
5 changes: 4 additions & 1 deletion ci/src/permute.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::collections::BTreeSet;

pub fn all<T>(input: &[T]) -> BTreeSet<BTreeSet<T>> where T: Ord + Eq + Clone {
pub fn all<T>(input: &[T]) -> BTreeSet<BTreeSet<T>>
where
T: Ord + Eq + Clone,
{
let mut permutations = BTreeSet::new();

if input.len() == 0 {
Expand Down
18 changes: 8 additions & 10 deletions ci/src/task.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use std::collections::BTreeSet;
use std::process::{
Command,
Stdio,
};
use std::process::{Command, Stdio};

pub type Feature = &'static str;

Expand Down Expand Up @@ -45,7 +42,7 @@ pub fn test(args: TestArgs) -> bool {
let features = args.features_string();

let mut command = Command::new("cargo");

command
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
Expand All @@ -65,13 +62,14 @@ pub fn test(args: TestArgs) -> bool {
}

println!("running {:?}", command);

let status = command
.status()
.expect("Failed to execute command");

let status = command.status().expect("Failed to execute command");

if !status.success() {
eprintln!("test execution failed for features: {}", features.as_ref().map(AsRef::as_ref).unwrap_or(""));
eprintln!(
"test execution failed for features: {}",
features.as_ref().map(AsRef::as_ref).unwrap_or("")
);
false
} else {
true
Expand Down
7 changes: 2 additions & 5 deletions examples/custom_default_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ If you want to control the logging output completely, see the `custom_logger` ex

#[macro_use]
extern crate log;
extern crate env_logger;

use env_logger::{Env, Builder};
use env_logger::{Builder, Env};

fn init_logger() {
let env = Env::default()
Expand All @@ -30,9 +29,7 @@ fn init_logger() {

let mut builder = Builder::from_env(env);

builder
.default_format_level(false)
.default_format_timestamp_nanos();
builder.format_level(false).format_timestamp_nanos();

builder.init();
}
Expand Down
61 changes: 30 additions & 31 deletions examples/custom_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,37 @@ $ export MY_LOG_STYLE=never
If you want to control the logging output completely, see the `custom_logger` example.
*/

#[macro_use]
extern crate log;
extern crate env_logger;

use std::io::Write;

use env_logger::{Env, Builder, fmt};

fn init_logger() {
let env = Env::default()
.filter("MY_LOG_LEVEL")
.write_style("MY_LOG_STYLE");

let mut builder = Builder::from_env(env);

// Use a different format for writing log records
// The colors are only available when the `termcolor` dependency is (which it is by default)
#[cfg(feature = "termcolor")]
builder.format(|buf, record| {
let mut style = buf.style();
style.set_bg(fmt::Color::Yellow).set_bold(true);

let timestamp = buf.timestamp();

writeln!(buf, "My formatted log ({}): {}", timestamp, style.value(record.args()))
});

builder.init();
}

#[cfg(all(feature = "termcolor", feature = "humantime"))]
fn main() {
use env_logger::{fmt, Builder, Env};
use std::io::Write;

fn init_logger() {
let env = Env::default()
.filter("MY_LOG_LEVEL")
.write_style("MY_LOG_STYLE");

Builder::from_env(env)
.format(|buf, record| {
let mut style = buf.style();
style.set_bg(fmt::Color::Yellow).set_bold(true);

let timestamp = buf.timestamp();

writeln!(
buf,
"My formatted log ({}): {}",
timestamp,
style.value(record.args())
)
})
.init();
}

init_logger();

info!("a log from `MyLogger`");
log::info!("a log from `MyLogger`");
}

#[cfg(not(all(feature = "termcolor", feature = "humantime")))]
fn main() {}
8 changes: 4 additions & 4 deletions examples/custom_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ If you only want to change the way logs are formatted, look at the `custom_forma

#[macro_use]
extern crate log;
extern crate env_logger;

use env_logger::filter::Filter;
use log::{Log, Metadata, Record, SetLoggerError};

struct MyLogger {
inner: Filter
inner: Filter,
}

impl MyLogger {
Expand All @@ -26,7 +26,7 @@ impl MyLogger {
let mut builder = Builder::from_env("MY_LOG_LEVEL");

MyLogger {
inner: builder.build()
inner: builder.build(),
}
}

Expand All @@ -50,7 +50,7 @@ impl Log for MyLogger {
}
}

fn flush(&self) { }
fn flush(&self) {}
}

fn main() {
Expand Down
1 change: 0 additions & 1 deletion examples/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ $ export MY_LOG_STYLE=never

#[macro_use]
extern crate log;
extern crate env_logger;

use env_logger::Env;

Expand Down
7 changes: 2 additions & 5 deletions examples/direct_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ Using `env_logger::Logger` and the `log::Log` trait directly.
This example doesn't rely on environment variables, or having a static logger installed.
*/

extern crate log;
extern crate env_logger;

fn record() -> log::Record<'static> {
let error_metadata = log::MetadataBuilder::new()
.target("myApp")
Expand Down Expand Up @@ -34,7 +31,7 @@ fn main() {
.filter(None, log::LevelFilter::Error)
.write_style(env_logger::WriteStyle::Never)
.build();

stylish_logger.log(&record());
unstylish_logger.log(&record());
}
}
1 change: 0 additions & 1 deletion examples/filters_from_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Specify logging filters in code instead of using an environment variable.

#[macro_use]
extern crate log;
extern crate env_logger;

fn main() {
env_logger::builder()
Expand Down

0 comments on commit 8209524

Please sign in to comment.