-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1134 from scrtlabs/stderr-logs-cosmwasmv1
Stderr logs cosmwasmv1
- Loading branch information
Showing
13 changed files
with
97 additions
and
277 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
use log::{Metadata, Record}; | ||
|
||
pub const LOG_LEVEL_ENV_VAR: &str = "LOG_LEVEL"; | ||
use std::env; | ||
|
||
pub struct SimpleLogger; | ||
|
||
impl log::Log for SimpleLogger { | ||
fn enabled(&self, _metadata: &Metadata) -> bool { | ||
// Not really needed since we set logging level at lib.rs in the init function | ||
true | ||
pub fn log_level_from_str(env_log_level: &str) -> Option<log::Level> { | ||
let uppercase = &env_log_level.to_uppercase()[..]; | ||
match uppercase { | ||
"ERROR" => Some(log::Level::Error), | ||
"WARN" => Some(log::Level::Warn), | ||
"INFO" => Some(log::Level::Info), | ||
"DEBUG" => Some(log::Level::Debug), | ||
"TRACE" => Some(log::Level::Trace), | ||
_ => None, | ||
} | ||
} | ||
|
||
fn log(&self, record: &Record) { | ||
println!( | ||
"{} [{}] {}", | ||
record.level(), | ||
record.target(), | ||
record.args() | ||
); | ||
pub fn get_log_level(default: log::Level) -> log::Level { | ||
let env_level = &env::var(LOG_LEVEL_ENV_VAR).unwrap_or_default(); | ||
match log_level_from_str(env_level) { | ||
Some(level) => { | ||
if level > default { | ||
default | ||
} else { | ||
level | ||
} | ||
} | ||
None => default, | ||
} | ||
|
||
fn flush(&self) {} | ||
} |
Oops, something went wrong.