Skip to content

Timestamp InfraScan CLI logs to show scan duration distribution#72

Draft
Natan-gal wants to merge 4 commits into
SolDevelo:mainfrom
Natan-gal:patch-5
Draft

Timestamp InfraScan CLI logs to show scan duration distribution#72
Natan-gal wants to merge 4 commits into
SolDevelo:mainfrom
Natan-gal:patch-5

Conversation

@Natan-gal
Copy link
Copy Markdown
Contributor

Summary

Added timestamped log messages to the InfraScan CLI to make it easier to see how long each major stage of the scan takes.

Changes

Added a log_with_timestamp() helper that prefixes messages with the current timestamp in the format:

[YYYY-MM-DD HH:MM:SS] Message

Added timestamped logs for the following stages:

  • Starting analysis
  • Starting directory scan
  • Directory scan completed
  • Generating report
  • Report generation completed
  • Saving report to file
  • Sending Slack notification
  • Evaluating fail conditions
  • Successful completion
  • Error handling

Purpose

InfraScan builds can take more than 20 minutes to complete. These timestamps make it possible to identify which parts of the process consume the most time.

Notes

External tool output (e.g. Docker Scout, Grype) is not modified, but the added timestamped logs provide clear boundaries around the major processing steps.

Added a logging function to print messages with timestamps, enhancing the visibility of the scanning process. Updated the main function to utilize this logging for various stages of execution.
Comment thread cli.py Outdated
from datetime import datetime


def log_with_timestamp(message: str) -> None:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Move this lower, so that it is next to other method definitions

Comment thread cli.py Outdated
[2026-10-10 16:23:34] Starting scan...
"""
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"[{timestamp}] {message}", flush=True)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we use logging for this? We configure logging below

Comment thread cli.py
traceback.print_exc()
sys.exit(1)

if __name__ == "__main__":
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is why this doesn't run, you removed the main check

Natan-gal added 2 commits May 19, 2026 15:21
Updated logging configuration to use INFO level and added timestamps to log messages. Replaced print statements with logger calls for error handling and notifications.
@igor-soldev
Copy link
Copy Markdown
Member

I think this PR is moving in the right direction, but it does not fully resolve issue #63 yet.

The goal in #63 was:

“Timestamp all the Infrascan logs … to see the distribution - as in which action takes how long.”

Right now only the logs emitted through logger.info(...) are timestamped. A significant part of the runtime output is still printed without timestamps, for example:

  • framework detection
  • Docker Scout scan progress
  • Docker Scout parse failures
  • image scan status messages

Current output still looks like:

Detected framework: terraform
Scanning image: nginx:alpine
Failed to parse Docker Scout output for nginx:alpine ...

without any timestamps attached.

That means we still cannot reliably determine where most of the 20+ minute runtime is spent, especially around container scanning which is likely one of the slowest stages.

I think to fully satisfy #63 we should:

  • migrate remaining operational print() calls to the configured logger
  • ensure all scanner/runtime stages emit timestamped logs
  • ideally add elapsed timing for long-running operations, e.g.
start = time.perf_counter()
logger.info(f"Scanning image: {image}")

# scan...

logger.info(
    f"Finished scanning {image} in {time.perf_counter() - start:.2f}s"
)

That would make the logs much more useful for profiling bottlenecks in CI/CD runs.

Also worth noting:
when using --format json, logs are still mixed into stdout before the JSON payload, which makes the output non-strict JSON for piping/tools like jq. Sending logs to stderr would improve CLI usability there as well.

Adding issue #63 as a reference because I think this PR partially addresses it, but doesn’t completely fulfill the original intent yet.

@igor-soldev igor-soldev marked this pull request as draft May 21, 2026 08:54
Add timestamped logging and execution duration metrics to InfraScan CLI.

This update improves log visibility during long-running scans by adding timestamps to log output and tracking execution time for key operations such as:

* directory scanning
* report generation
* report saving
* Slack notifications
* total CLI execution

The goal is to make GitHub Actions and CI logs easier to debug and help identify performance bottlenecks during large scans.
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.

3 participants