Skip to content

Improve logging logic#44

Open
Gurjaka wants to merge 2 commits into
pretty-terminal:mainfrom
Gurjaka:logging
Open

Improve logging logic#44
Gurjaka wants to merge 2 commits into
pretty-terminal:mainfrom
Gurjaka:logging

Conversation

@Gurjaka
Copy link
Copy Markdown
Contributor

@Gurjaka Gurjaka commented Feb 17, 2026

We had cases where we wanted to debug code using the pretty_log system. Our logging levels are defined as:

enum log_level {
    PRETTY_ERROR,
    PRETTY_WARN,
    PRETTY_INFO,
    PRETTY_DEBUG
};

The main issue was that PRETTY_DEBUG logs were still emitted in RELEASE builds.

Note: Logging can be expensive, and unnecessary debug statements can significantly impact the emulator’s performance.

This PR introduces two commits:

  1. Compile-time debug filtering:
    Using the C preprocessor, PRETTY_DEBUG logs are only included when the binary is built with DEBUG_MODE. This ensures debug logs are removed from release builds entirely.

  2. Time caching optimization:
    pretty_log_get_time() now caches the last retrieved time (time_t last) and only updates when the current time (time_t now) changes. This eliminates redundant syscalls, reducing overhead in frequent logging scenarios.

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.

1 participant