ZFFramework
 
Loading...
Searching...
No Matches
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(...)
 thread-safe log utility
 
#define ZFLogTrim(...)
 see ZFLog
 

Typedefs

typedef zfstring(* ZFLogHeaderFunc) (const ZFCallerInfo &callerInfo)
 see ZFLogHeader
 

Functions

ZFMutexZFLogMutex ()
 mutex used by ZFLog, you may use this lock to prevent your log actions from being interrupted
 
zfstring ZFLogHeaderDefault (const ZFCallerInfo &callerInfo)
 see ZFLogHeader
 
zfboolZFLogHeaderDefault_logTime (void)
 see ZFLogHeader, enabled by default
 
void ZFLogHeaderDefault_logTime (zfbool const &v)
 see ZFLogHeaderDefault_logTime
 
zfboolZFLogHeaderDefault_logCaller (void)
 see ZFLogHeader, enabled by default, set to false if v_ZFLogLevel::e_Verbose is not active
 
void ZFLogHeaderDefault_logCaller (zfbool const &v)
 see ZFLogHeaderDefault_logCaller
 
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
 

Variables

ZFLogHeaderFunc ZFLogHeader
 callback to obtain log header for ZFLog
 

Detailed Description

thread-safe log utility

Macro Definition Documentation

◆ ZFLog

#define ZFLog ( ...)

thread-safe log utility

typical usage:

// output anything with ZFLogHeader
ZFLog() << anything;
ZFLog("formated: %s", someText);
// or, trim version without ZFLogHeader
ZFLogTrim() << anything;
ZFLogTrim("formated: %s", someText);
#define ZFLog(...)
thread-safe log utility
Definition ZFLog.h:77
#define ZFLogTrim(...)
see ZFLog
Definition ZFLog.h:80

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:106

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

Variable Documentation

◆ ZFLogHeader

ZFLogHeaderFunc ZFLogHeader
extern

callback to obtain log header for ZFLog

set to ZFLogHeaderDefault at ZFLevelZFFrameworkStatic, set to null to disable header info
by default, the header would looks like this (not ensured):
"12:34:56.123 [file scope::function (line)] "
the default header can be configured by: