Skip to content

Commit

Permalink
recover default example and add new one for wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
huangjj27 committed Nov 6, 2020
1 parent cd6372c commit bc6d841
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -27,7 +27,7 @@ humantime = { version = "2.0.0", optional = true }
atty = { version = "0.2.5", optional = true }

[target.wasm32-unknown-unknown.dependencies]
wasm-bindgen = "*"
wasm-bindgen = "^0.2.64"

[[test]]
name = "regexp_filter"
Expand Down
11 changes: 0 additions & 11 deletions examples/default.rs
Expand Up @@ -20,9 +20,6 @@ extern crate log;

use env_logger::Env;

#[cfg(all(target_arch = "wasm32", target_vendor = "unknown"))]
use wasm_bindgen::prelude::wasm_bindgen;

fn main() {
// The `Env` lets us tweak what the environment
// variables to read are and what the default
Expand All @@ -39,11 +36,3 @@ fn main() {
warn!("some warning log");
error!("some error log");
}

#[cfg_attr(
all(target_arch = "wasm32", target_vendor = "unknown"),
wasm_bindgen(start)
)]
pub fn start() {
main();
}
49 changes: 49 additions & 0 deletions examples/default_wasm.rs
@@ -0,0 +1,49 @@
/*!
Using `env_logger`.
Before running this example, try setting the `MY_LOG_LEVEL` environment variable to `info`:
```no_run,shell
$ export MY_LOG_LEVEL='info'
```
Also try setting the `MY_LOG_STYLE` environment variable to `never` to disable colors
or `auto` to enable them:
```no_run,shell
$ export MY_LOG_STYLE=never
```
*/

#[macro_use]
extern crate log;

use env_logger::Env;

#[cfg(all(target_arch = "wasm32", target_vendor = "unknown"))]
use wasm_bindgen::prelude::wasm_bindgen;

fn main() {
// The `Env` lets us tweak what the environment
// variables to read are and what the default
// value is if they're missing
let env = Env::default()
.filter_or("MY_LOG_LEVEL", "trace")
.write_style_or("MY_LOG_STYLE", "always");

env_logger::init_from_env(env);

trace!("some trace log");
debug!("some debug log");
info!("some information log");
warn!("some warning log");
error!("some error log");
}

#[cfg_attr(
all(target_arch = "wasm32", target_vendor = "unknown"),
wasm_bindgen(start)
)]
pub fn start() {
main();
}

0 comments on commit bc6d841

Please sign in to comment.