|
ZeroErr
|
LOG is a macro help you to LOG structured data into a file and record the meta data about it (FILE, LINE, FUNCTION and LOG messages).
All the data that put in LOG should be on disk and saved.
There 5 levels of log information: INFO, LOG, WARNING, ERROR, and FATAL.
The INFO level will discard the information if there is no other LOG, WARNING, ERROR, and FATAL happens in the context.
Note: LOG FATAL will cause the program terminate
Log only on a function, or on a file, or on a module
You can use info to get some information and later use LOG macro to record them.
With ENABLE_THREAD_SAFE, logging macros can write to a shared LogStream while another thread calls flush(). Arguments and timestamps are prepared before taking the stream mutex; complete records are published under that mutex. Blocks hold approximately 64 KiB, file writes are batched per block, and stored arguments are destroyed when records are released.
Configure setFileLogger() and setFlushWhenFull() before starting producers for batched output, and call flush() after joining them. The default immediate flush favors output latency. Manual flushing retains records and can grow memory without bound. setAsyncLog() does not currently start a background writer.
Configure callbacks and sinks before starting workers. Iteration, queries, and manual metadata assignment after the low-level push() / log() APIs require external synchronization, as do the counters in *_EVERY_* / *_FIRST* macros. Concurrent INFO context output through the shared stderr printer also requires external synchronization. The use_lock_free field remains for source compatibility; publication uses the stream mutex. Formatting callbacks run under that mutex and must not log back to the same stream.
With BUILD_TEST, log_concurrency checks record integrity with 1/2/4/8 producers, all flush modes, concurrent flushing, block transitions, and destructor flushing. Run log_concurrency benchmark to measure file throughput with minimal formatting, including final draining and without a separate flushing thread.