-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
7 deletions.
There are no files selected for viewing
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,16 +1,24 @@ | ||
use log::SetLoggerError; | ||
|
||
/// Failure of setting logger. | ||
pub(crate) enum LoggerError { | ||
/// The user didn't enable the "builtin_env_logger" feature. | ||
NoBuiltinLogger, | ||
/// Error happened while setting the logger. | ||
SetLoggerError(SetLoggerError), | ||
} | ||
|
||
/// Attempt to init a env_logger for MMTk. | ||
/// Does nothing if the "builtin_env_logger" feature is disabled. | ||
pub fn try_init() -> Result<(), SetLoggerError> { | ||
pub fn try_init() -> Result<(), LoggerError> { | ||
cfg_if::cfg_if! { | ||
if #[cfg(feature = "builtin_env_logger")] { | ||
env_logger::try_init_from_env( | ||
// By default, use info level logging. | ||
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"), | ||
) | ||
).map_err(LoggerError::SetLoggerError) | ||
} else { | ||
Ok(()) | ||
Err(LoggerError::NoBuiltinLogger) | ||
} | ||
} | ||
} |