Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlight Cached state in console #15801

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/prefect/logging/highlighters.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class StateHighlighter(RegexHighlighter):
highlights = [
rf"(?P<{state.value.lower()}_state>{state.value.title()})"
for state in StateType
] + [
r"(?P<cached_state>Cached)(?=\(type=COMPLETED\))" # Highlight only "Cached"
]


Expand Down
165 changes: 82 additions & 83 deletions src/prefect/logging/logging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,107 +9,106 @@ version: 1
disable_existing_loggers: False

formatters:
simple:
format: "%(asctime)s.%(msecs)03d | %(message)s"
datefmt: "%H:%M:%S"
simple:
format: "%(asctime)s.%(msecs)03d | %(message)s"
datefmt: "%H:%M:%S"

standard:
(): prefect.logging.formatters.PrefectFormatter
format: "%(asctime)s.%(msecs)03d | %(levelname)-7s | %(name)s - %(message)s"
flow_run_fmt: "%(asctime)s.%(msecs)03d | %(levelname)-7s | Flow run %(flow_run_name)r - %(message)s"
task_run_fmt: "%(asctime)s.%(msecs)03d | %(levelname)-7s | Task run %(task_run_name)r - %(message)s"
datefmt: "%H:%M:%S"
standard:
(): prefect.logging.formatters.PrefectFormatter
format: "%(asctime)s.%(msecs)03d | %(levelname)-7s | %(name)s - %(message)s"
flow_run_fmt: "%(asctime)s.%(msecs)03d | %(levelname)-7s | Flow run %(flow_run_name)r - %(message)s"
task_run_fmt: "%(asctime)s.%(msecs)03d | %(levelname)-7s | Task run %(task_run_name)r - %(message)s"
datefmt: "%H:%M:%S"

debug:
format: "%(asctime)s.%(msecs)03d | %(levelname)-7s | %(threadName)-12s | %(name)s - %(message)s"
datefmt: "%H:%M:%S"
debug:
format: "%(asctime)s.%(msecs)03d | %(levelname)-7s | %(threadName)-12s | %(name)s - %(message)s"
datefmt: "%H:%M:%S"

json:
class: prefect.logging.formatters.JsonFormatter
format: "default"
json:
class: prefect.logging.formatters.JsonFormatter
format: "default"

# filters:
# Define any custom filters to drops records containing
# sensitive information
# my_filter:
# class: your_module.FilterClass
# Define any custom filters to drops records containing
# sensitive information
# my_filter:
# class: your_module.FilterClass

handlers:

# The handlers we define here will output all logs they receive by default
# but we include the `level` so it can be overridden by environment

console:
level: 0
class: prefect.logging.handlers.PrefectConsoleHandler
formatter: standard
styles:
log.web_url: bright_blue
log.local_url: bright_blue

log.info_level: cyan
log.warning_level: yellow3
log.error_level: red3
log.critical_level: bright_red

log.completed_state: green
log.cancelled_state: yellow3
log.failed_state: red3
log.crashed_state: bright_red

log.flow_run_name: magenta
log.flow_name: bold magenta

api:
level: 0
class: prefect.logging.handlers.APILogHandler


debug:
level: 0
class: logging.StreamHandler
formatter: debug
# The handlers we define here will output all logs they receive by default
# but we include the `level` so it can be overridden by environment

console:
level: 0
class: prefect.logging.handlers.PrefectConsoleHandler
formatter: standard
styles:
log.web_url: bright_blue
log.local_url: bright_blue

log.info_level: cyan
log.warning_level: yellow3
log.error_level: red3
log.critical_level: bright_red

log.completed_state: green
log.cancelled_state: yellow3
log.failed_state: red3
log.crashed_state: bright_red
log.cached_state: bright_blue

log.flow_run_name: magenta
log.flow_name: bold magenta

api:
level: 0
class: prefect.logging.handlers.APILogHandler

debug:
level: 0
class: logging.StreamHandler
formatter: debug

loggers:
prefect:
level: "${PREFECT_LOGGING_LEVEL}"
prefect:
level: "${PREFECT_LOGGING_LEVEL}"

prefect.extra:
level: "${PREFECT_LOGGING_LEVEL}"
handlers: [api]
propagate: false
prefect.extra:
level: "${PREFECT_LOGGING_LEVEL}"
handlers: [api]
propagate: false

prefect.flow_runs:
level: NOTSET
handlers: [api]
prefect.flow_runs:
level: NOTSET
handlers: [api]

prefect.task_runs:
level: NOTSET
handlers: [api]
prefect.task_runs:
level: NOTSET
handlers: [api]

prefect.server:
level: "${PREFECT_SERVER_LOGGING_LEVEL}"
prefect.server:
level: "${PREFECT_SERVER_LOGGING_LEVEL}"

prefect.client:
level: "${PREFECT_LOGGING_LEVEL}"
prefect.client:
level: "${PREFECT_LOGGING_LEVEL}"

prefect.infrastructure:
level: "${PREFECT_LOGGING_LEVEL}"
prefect.infrastructure:
level: "${PREFECT_LOGGING_LEVEL}"

prefect._internal:
level: "${PREFECT_LOGGING_INTERNAL_LEVEL}"
propagate: false
handlers: [debug]
prefect._internal:
level: "${PREFECT_LOGGING_INTERNAL_LEVEL}"
propagate: false
handlers: [debug]

uvicorn:
level: "${PREFECT_SERVER_LOGGING_LEVEL}"
uvicorn:
level: "${PREFECT_SERVER_LOGGING_LEVEL}"

fastapi:
level: "${PREFECT_SERVER_LOGGING_LEVEL}"
fastapi:
level: "${PREFECT_SERVER_LOGGING_LEVEL}"

# The root logger: any logger without propagation disabled sends to here as well
root:
# By default, we display warning level logs from any library in the console
# to match Python's default behavior while formatting logs nicely
level: WARNING
handlers: [console]
# By default, we display warning level logs from any library in the console
# to match Python's default behavior while formatting logs nicely
level: WARNING
handlers: [console]
22 changes: 16 additions & 6 deletions tests/test_highlighters.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,25 @@ def test_highlight_name(name, lower):
]


@pytest.mark.parametrize("state", ["completed", "cancelled", "failed", "crashed"])
@pytest.mark.parametrize(
"state", ["completed", "cancelled", "failed", "crashed", "cached"]
)
def test_highlight_state(state):
keyword = state.title()
text = Text(f"Flow run 'polite-jackal' - Finished in state {keyword}()")
if state == "cached":
text = Text(
"Flow run 'polite-jackal' - Finished in state Cached(type=COMPLETED)"
)
expected_span = Span(
45, 51, "state.cached_state"
) # Only "Cached" is highlighted
else:
keyword = state.title()
text = Text(f"Flow run 'polite-jackal' - Finished in state {keyword}()")
expected_span = Span(45, 45 + len(keyword), f"state.{state}_state")

highlighter = StateHighlighter()
highlighter.highlight(text)
assert text.spans == [
Span(45, 45 + len(keyword), f"state.{state}_state"),
]
assert text.spans == [expected_span]


def test_highlight_console():
Expand Down
Loading