Skip to content

[Bugfix] Update log_level parsing to use parse_level from #27 #28

@zhaozuy

Description

@zhaozuy

Currently StandardSupervisor class method _setup_logger has the same issue fixed by #26 #27 where it cannot handle case where log level env variable is specified as an int (read as string).

We want to update this so it can handle this case as well as silently fallback to a specific level (e.g. ERROR) if parse fails.

def _setup_logging(self) -> None:
"""Configure logging based on environment."""
log_level = os.getenv("LOG_LEVEL", "INFO").upper()
self.logger.setLevel(getattr(logging, log_level, logging.INFO))

See parse_level:

def parse_level(level: str) -> Union[int, str]:
"""Parse a log level string into a valid logging level.
Args:
level: Log level string to parse.
Returns:
Valid logging level.
"""
# Convert level to uppercase
level = level.upper()
# Convert numeric log level string to int so `setLevel` can recognize it
try:
return int(level)
except ValueError:
return level

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions