ZFFramework
Loading...
Searching...
No Matches
Classes | Macros | Functions
ZFLog.h File Reference

thread-safe log utility More...

#include "ZFLogLevel.h"
#include "ZFMutex.h"
#include "ZFOutputForFormat.h"

Go to the source code of this file.

Classes

class  ZFLogFormat
 output format for zfLog More...
 

Macros

#define ZFLOG_HEADER_STRING
 a convenient debug header string
 
#define zfLog(...)
 thread-safe log utility
 
#define zfLogTrim(...)
 see zfLog
 

Functions

ZFMutexZFLogMutex ()
 mutex used by zfLog, you may use this lock to prevent your log actions from being interrupted
 
void ZFLogFormatDefault (ZFLogFormat *fmt)
 change default log format
 
ZFLogFormatZFLogFormatDefault ()
 get default log format
 
zfstring zfLogCurTimeString ()
 get a string contains current time with format HH:mm:ss.SSS
 

Detailed Description

thread-safe log utility

Macro Definition Documentation

◆ ZFLOG_HEADER_STRING

#define ZFLOG_HEADER_STRING

a convenient debug header string

typically looks like this (not ensured):
"timestamp [file scope::function (line)] "

◆ zfLog

#define zfLog ( ...)

thread-safe log utility

typical usage:

// output anything with ZFLOG_HEADER_STRING
zfLog() << anything;
zfLog("formated: %s", someText);
// or, trim version without ZFLOG_HEADER_STRING
zfLogTrim() << anything;
zfLogTrim("formated: %s", someText);
#define zfLogTrim(...)
see zfLog
Definition ZFLog.h:67
#define zfLog(...)
thread-safe log utility
Definition ZFLog.h:64

ZFLog is actually an output callback, you can output anything that ZFOutput supported
final log content would be written to ZFOutputDefault, which can be easily redirected to other output destinations
ZFLog is thread-safe, implemented by ZFLogMutex

by default, ZFLog would automatically:

  • append space between each output
  • append endl after last output

these behavior can be changed by:

fmt->autoEndl(xxx);
static zfanyT< ZFOutputFormat > getFormat(const ZFCallback &output)
try access the output format passed to ZFOutputForFormat, return null if not available
see zfany
Definition zfany.h:161

and they would be reset to default state after each zfLog call

Function Documentation

◆ ZFLogMutex()

ZFMutex * ZFLogMutex ( )
extern

mutex used by zfLog, you may use this lock to prevent your log actions from being interrupted

note, the mutex would be initialized only after ZFLevelZFFrameworkEssential