Skip to content

Conversation

ChouraquiBen
Copy link
Contributor

@ChouraquiBen ChouraquiBen commented Aug 18, 2025

Reason for Proposed Changes

  • We don't have context to logs which makes them difficult to use.

Proposed Changes

  • Add context to logs

Currently, the logs have only the message attached to them for the developers to gather informations on what is happening.

The change here is to add some "context" to those logs. This means that attached to the logs, there will be not only the message but also the repository, the branch and the commit sha, also the org and the org_id.

Here are some logs with the new infos on them: https://dd.datad0g.com/logs/livetail?query=service%3Aiac-scanning&refresh_mode=paused&storage=driveline&from_ts=1756208553000&to_ts=1756209453000&live=false

I submit this contribution under the Apache-2.0 license.

@ChouraquiBen ChouraquiBen force-pushed the benjamin.chouraqui/add-context-to-logs branch 2 times, most recently from e3fe057 to 405a4cd Compare August 20, 2025 14:04
Refs: K9VULN-6211
Refs: K9VULN-6211
Also decided to make te output prettier
Corrected a log to make it have an actual level

Refs: K9VULN-6211
also added missing parameter to some test

Refs: K9VULN-7714
@ChouraquiBen ChouraquiBen force-pushed the benjamin.chouraqui/add-context-to-logs branch from af016c8 to abe41ed Compare August 21, 2025 12:02
@ChouraquiBen
Copy link
Contributor Author

ChouraquiBen commented Aug 21, 2025

Logs on the Explorer with the added context.
Screenshot 2025-08-21 at 15 14 31

@ChouraquiBen
Copy link
Contributor Author

Logs on KICS locally (when the consolePrint flag is passed as true in the args)
Screenshot 2025-08-21 at 15 19 45

Copy link
Member

@chouze chouze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small comments. Overall if it works then it should be a big help!

for index := range summary.Queries {
idx := len(summary.Queries) - index - 1
if summary.Queries[idx].Severity == model.SeverityTrace {
continue
}

fmt.Printf(
(&logger).Info().Msgf(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless I'm missing something, I don't think you need to grab a pointer to use the logger

@@ -167,13 +169,13 @@ func PrintResult(summary *model.Summary, printer *Printer, usingCustomQueries bo
return nil
}

func printSeverityCounter(severity string, counter int, printColor color.RGBColor) {
fmt.Printf("%s: %d\n", printColor.Sprint(severity), counter)
func printSeverityCounter(severity string, counter int, logger *zerolog.Logger) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally it's fine to just grab the logger again, instead of passing it along

@ChouraquiBen ChouraquiBen force-pushed the benjamin.chouraqui/add-context-to-logs branch from 056878d to 2e3d1d7 Compare August 26, 2025 08:32
@ChouraquiBen ChouraquiBen merged commit 6e1a3ad into main Aug 26, 2025
6 checks passed
@ChouraquiBen ChouraquiBen deleted the benjamin.chouraqui/add-context-to-logs branch August 26, 2025 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants