Skip to content

Commit

Permalink
Fix LoggingConfig parsing of warning level
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Jan 14, 2024
1 parent 2be89d7 commit 9ecc40c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
3 changes: 2 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ None
None

### Fixes
None
- Fixed `LoggingConfig` parsing of `WARNING` log level (was not being recognized), thanks for reporting @davidsblom

---

# NautilusTrader 1.183.0 Beta

Released on 12th January 2024 (UTC).
Expand Down
16 changes: 16 additions & 0 deletions nautilus_core/common/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,22 @@ mod tests {
)
}

#[rstest]
fn log_config_parsing2() {
let config = LoggerConfig::from_spec("stdout=Warn;print_config;fileout=Error;");
assert_eq!(
config,
LoggerConfig {
stdout_level: LevelFilter::Warn,
fileout_level: LevelFilter::Error,
component_level: HashMap::new(),
is_colored: false,
is_bypassed: false,
print_config: true,
}
)
}

#[rstest]
fn test_logging_to_file() {
let config = LoggerConfig {
Expand Down
13 changes: 10 additions & 3 deletions nautilus_trader/config/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def resolve_path(path: str) -> type:
return cls


def normalize_log_level_string(level_str: str) -> str:
level_str = level_str.lower()
if level_str == "warning":
level_str = "warn"
return level_str


def msgspec_encoding_hook(obj: Any) -> Any:
if isinstance(obj, Decimal):
return str(obj)
Expand Down Expand Up @@ -839,12 +846,12 @@ def spec_string(self) -> str:
str
"""
config_str = f"stdout={self.log_level.lower()}"
config_str = f"stdout={normalize_log_level_string(self.log_level)}"
if self.log_level_file:
config_str += f";fileout={self.log_level_file.lower()}"
config_str += f";fileout={normalize_log_level_string(self.log_level_file)}"
if self.log_component_levels:
for component, level in self.log_component_levels.items():
config_str += f";{component}={level.lower()}"
config_str += f";{component}={normalize_log_level_string(level)}"
if self.log_colors:
config_str += ";is_colored"
if self.bypass_logging:
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/config/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ def test_logging_config_spec_string_with_default_config() -> None:
def test_logging_config_spec_string() -> None:
# Arrange
logging = LoggingConfig(
log_level="INFO",
log_level_file="DEBUG",
log_level="WARNING",
log_level_file="ERROR",
log_component_levels={
"RiskEngine": "ERROR",
"OrderEmulator": "DEBUG",
Expand All @@ -382,5 +382,5 @@ def test_logging_config_spec_string() -> None:

# Assert
assert (
config_str == "stdout=info;fileout=debug;RiskEngine=error;OrderEmulator=debug;print_config"
config_str == "stdout=warn;fileout=error;RiskEngine=error;OrderEmulator=debug;print_config"
)

0 comments on commit 9ecc40c

Please sign in to comment.