ocean.util.log.PeriodicTrace

Periodic console tracer

Periodic console tracer - writes messages to the console limited to a specified update interval. This can be used to safely limit the number of writes to the console. The write is done using either Stderr or ocean.util.log.StaticTrace, depending on the value of the struct's static_display member.

More...

Members

Structs

PeriodicTracer
struct PeriodicTracer

PeriodicTracer struct.

Variables

PeriodicTrace
PeriodicTracer PeriodicTrace;

Two shared instances of the PeriodicTracer struct, one with a normal "streaming" display via Trace, and one with a static updating display via StaticTrace.

StaticPeriodicTrace
PeriodicTracer StaticPeriodicTrace;
Undocumented in source.

Detailed Description

Two global instances of this struct exist for convenience: PeriodicTrace and StaticPeriodicTrace. The latter has the static_display flag set to true.

Usage example with the global instance:

import ocean.util.log.PeriodicTrace;

const ulong trace_interval = 500_000; // only update display after at least half a second has passed

for ( uint i; i < uint.max; i++ )
{
    StaticPeriodicTrace.format(trace_interval, "{}", i);
}

A local instance of the PeriodicTracer struct may be useful in situations where two or more separate periodic outputs are required each with a different update interval.

Usage example with a local instance:

import ocean.util.log.PeriodicTrace;

PeriodicTracer trace1;
trace1.interval = 500_000; // only update display after at least half a second has passed

PeriodicTracer trace2;
trace2.interval = 5_000_000; // only update display after at least 5 seconds have passed

for ( uint i; i < uint.max; i++ )
{
    trace1.format("{}", i);
    trace2.format("{}", i);
}

Note: this struct automatically calls Trace.flush / StaticTrace.flush after updating.

Meta

License

Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. Alternatively, this file may be distributed under the terms of the Tango 3-Clause BSD License (see LICENSE_BSD.txt for details).