GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add JSON logging format support for scan jobs and enforcer by moshemorad · Pull Request #539 · robusta-dev/krr

Add JSON logging format support for scan jobs and enforcer #539

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.

Sign up for GitHub

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

Merged
moshemorad merged 4 commits into main from claude/json-log-format-runner-vqbzst
Jul 15, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Add JSON logging format support for scan jobs and enforcer #539

Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
7bba816
Add JSON log format for scan jobs and enforcer (ROB-459)
claude Jul 12, 2026
4c697dd
Regenerate poetry.lock with Poetry 1.8.5
claude Jul 12, 2026
2657080
Add python-json-logger to pip requirements files
claude Jul 14, 2026
cefb2b2
Move pythonjsonlogger import to module top level
claude Jul 14, 2026
File filter
Filter by extension


Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

13 changes: 12 additions & 1 deletion 13 enforcer/enforcer_main.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,18 @@
# Configure logging
logger = logging.getLogger()
logHandler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
# When ENABLE_JSON_LOGS_FORMAT is set, emit JSON logs (one object per line) so
# scrapers like Filebeat can index them; otherwise keep the plain text format.
if os.environ.get("ENABLE_JSON_LOGS_FORMAT", "false").strip().lower() in ("true", "1", "yes"):
from pythonjsonlogger.json import JsonFormatter
Comment thread
moshemorad marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.


formatter: logging.Formatter = JsonFormatter(
fmt="%(asctime)s %(levelname)s %(name)s %(filename)s %(lineno)d %(funcName)s %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S",
rename_fields={"levelname": "severity"},
)
else:
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
logHandler.setFormatter(formatter)
logger.addHandler(logHandler)
logger.setLevel(os.environ.get("LOG_LEVEL", "INFO"))
Expand Down
1 change: 1 addition & 0 deletions 1 enforcer/requirements.txt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ supabase==2.5
PyYAML==6.0.1
cachetools==5.3.3
prometheus-client==0.20.0
python-json-logger==3.3.0
kubernetes==26.1.0
pyasn1>=0.6.2
urllib3==2.7.0
2 changes: 2 additions & 0 deletions 2 helm/krr-enforcer/templates/enforcer.yaml
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ spec:
value: "/etc/webhook/certs/tls.crt"
- name: LOG_LEVEL
value: {{ .Values.logLevel | quote }}
- name: ENABLE_JSON_LOGS_FORMAT
value: {{ .Values.global.enableJsonLogsFormat | default .Values.enableJsonLogsFormat | default false | quote }}
{{- if .Values.certificate }}
- name: CERTIFICATE
value: {{ .Values.certificate | quote }}
Expand Down
7 changes: 7 additions & 0 deletions 7 helm/krr-enforcer/values.yaml
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
certificate: "" # base64 encoded
logLevel: INFO
# When true, logs are emitted as JSON (one object per line) instead of plain
# text. Useful for log scrapers like Filebeat. Defaults to false.
enableJsonLogsFormat: false

# Values shared with/from a parent umbrella chart. Declared so templates can
# safely reference .Values.global.* when the chart is installed standalone.
global: {}

# Certificate job configuration
certJob:
Expand Down
16 changes: 15 additions & 1 deletion 16 poetry.lock
Show comments
View file
Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

1 change: 1 addition & 0 deletions 1 pyproject.toml
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ urllib3 = "^2.7.0"
setuptools = "^80.9.0"
zipp = "^3.19.1"
tenacity = "^9.0.0"
python-json-logger = "^3.0.0"


[tool.poetry.group.dev.dependencies]
Expand Down
1 change: 1 addition & 0 deletions 1 requirements.txt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pydantic==1.10.15 ; python_version >= "3.10" and python_full_version < "3.13"
pygments==2.20.0 ; python_version >= "3.10" and python_full_version < "3.13"
pyparsing==3.1.2 ; python_version >= "3.10" and python_full_version < "3.13"
python-dateutil==2.9.0.post0 ; python_version >= "3.10" and python_full_version < "3.13"
python-json-logger==3.3.0 ; python_version >= "3.10" and python_full_version < "3.13"
pytz==2024.1 ; python_version >= "3.10" and python_full_version < "3.13"
pyyaml==6.0.1 ; python_version >= "3.10" and python_full_version < "3.13"
regex==2023.12.25 ; python_version >= "3.10" and python_full_version < "3.13"
Expand Down
29 changes: 23 additions & 6 deletions 29 robusta_krr/core/models/config.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
import os
import sys
from typing import Any, Literal, Optional, Union

Expand Down Expand Up @@ -203,12 +204,28 @@ def set_config(config: Config) -> None:
global _config

_config = config
logging.basicConfig(
level="NOTSET",
format="%(message)s",
datefmt="[%X]",
handlers=[RichHandler(console=config.logging_console)],
)
# ENABLE_JSON_LOGS_FORMAT is env-driven (never a CLI flag) so the
# interactive CLI keeps its Rich output, while in-cluster scan jobs can
# emit JSON logs (one object per line) for scrapers like Filebeat.
if os.environ.get("ENABLE_JSON_LOGS_FORMAT", "false").strip().lower() in ("true", "1", "yes"):
from pythonjsonlogger.json import JsonFormatter
Comment thread
moshemorad marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.


handler = logging.StreamHandler(config.logging_console.file)
handler.setFormatter(
JsonFormatter(
fmt="%(asctime)s %(levelname)s %(name)s %(filename)s %(lineno)d %(funcName)s %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S",
rename_fields={"levelname": "severity"},
)
)
logging.basicConfig(level="NOTSET", handlers=[handler], force=True)
else:
logging.basicConfig(
level="NOTSET",
format="%(message)s",
datefmt="[%X]",
handlers=[RichHandler(console=config.logging_console)],
)
logging.getLogger("").setLevel(logging.CRITICAL)
logger.setLevel(logging.DEBUG if config.verbose else logging.CRITICAL if config.quiet else logging.INFO)

Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402860 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.