Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FEAT] Deterministic thread id #898

@steve-lorimer

Description

@steve-lorimer

Is your feature request related to a problem? Please describe.
Yes. I would like a deterministic log output so that repeated runs of an application with the same input results in the same output.

As an example: when doing repeated runs of a backtest, where the logged timestamp is controlled by the timestamps in the recorded market data file, the log output is always exactly the same except for one thing, the thread_id.

Describe the solution you'd like
Rather than always using the current pid/tid, have an option to use an incrementing integer

QUILL_NODISCARD QUILL_EXPORT QUILL_ATTRIBUTE_USED inline uint32_t get_thread_id() noexcept
{
#if defined(QUILL_USE_SEQUENTIAL_THREAD_ID)
    static std::atomic<uint32_t> next_thread_id = 0;
    return ++next_thread_id;
#elif defined(__CYGWIN__)
    ... etc
#endif
}

Additional context
This means that repeated runs will always have eg: 1 for the main thread, and 2 for next next spawned thread, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions