bux API Reference 1.9.0
Static library of whatever are seen required in general purpose but not directly supported from Modern C++. Or whatever reusable originated from my side projects.
Loading...
Searching...
No Matches
Logger.h File Reference
#include "SyncLog.h"
#include "XPlatform.h"
#include <format>
#include <optional>
#include <string_view>
Include dependency graph for Logger.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  bux::C_EntryLog
 Log on both declaration point and end of block scope with an unique id. More...
 

Namespaces

namespace  bux
 THE common namespace of bux library.
 
namespace  bux::user
 Function prototypes declared in this subnamespace are required to be implemented by user so that functions declared under namespace bux in the same header can be linked properly without errors.
 

Macros

#define _gluePair_(x, y)
 
#define SCOPELOG_(line, scope)
 
#define SCOPELOGX_(line, scope, fmtStr, ...)
 
#define DEF_LOGGER_HEAD_   namespace bux { namespace user { I_SyncLog &logger() {
 
#define DEF_LOGGER_TAIL_(x)
 
#define LOG(ll, fmtStr, ...)
 
#define LOG_RAW(fmtStr, ...)
 
#define SCOPELOG(scope)
 
#define SCOPELOGX(scope, fmtStr, ...)
 
#define LOGGER_USE_LOCAL_TIME_   true
 
#define DEF_LOGGER_OSTREAM(out, ...)
 
#define DEF_LOGGER_COUT(...)
 
#define DEF_LOGGER_CERR(...)
 
#define DEF_LOGGER_FILE(path, ...)
 
#define DEF_LOGGER_FILES(pathfmt, ...)
 
#define DEF_FALLBACK_LOGGER_FILES(fsize_in_bytes, fallbackPaths)
 
#define DEF_PARA_LOGGER
 
#define FUNLOG   SCOPELOG(CUR_FUNC_)
 
#define FUNLOGX(fmtStr, ...)
 

Functions

I_SyncLogbux::logger ()
 
std::ostream & bux::stamp (const C_UseLog &u, E_LogLevel level)
 
I_SyncLogbux::user::logger ()
 

Macro Definition Documentation

◆ _gluePair_

#define _gluePair_ ( x,
y )
Value:
x##y

Definition at line 69 of file Logger.h.

◆ DEF_FALLBACK_LOGGER_FILES

#define DEF_FALLBACK_LOGGER_FILES ( fsize_in_bytes,
fallbackPaths )
Value:
namespace bux { namespace user { \
C_PathFmtLogSnap g_snap{LOGGER_USE_LOCAL_TIME_}; \
C_ReenterableOstreamSnap g_ros{g_snap.configPath(fsize_in_bytes, fallbackPaths)}; \
I_SyncLog &logger() { \
static C_SyncLogger l_{g_ros, LOGGER_USE_LOCAL_TIME_}; \
DEF_LOGGER_TAIL_(l_)
#define LOGGER_USE_LOCAL_TIME_
Definition Logger.h:84
I_SyncLog & logger()
THE common namespace of bux library.
Definition AtomiX.cpp:3
C_ReenterableLogger< C_PersistedSnapHolder > C_ReenterableOstreamSnap
Definition SyncLog.h:194
Examples
test/smoke_timelog.cpp.

Definition at line 127 of file Logger.h.

◆ DEF_LOGGER_CERR

#define DEF_LOGGER_CERR ( ...)
Value:
DEF_LOGGER_OSTREAM(std::cerr, ##__VA_ARGS__)
#define DEF_LOGGER_OSTREAM(out,...)
Definition Logger.h:101
Examples
test/smoke_cerrlog.cpp.

Definition at line 108 of file Logger.h.

◆ DEF_LOGGER_COUT

#define DEF_LOGGER_COUT ( ...)
Value:
DEF_LOGGER_OSTREAM(std::cout, ##__VA_ARGS__)
Examples
test/smoke_coutlog.cpp.

Definition at line 107 of file Logger.h.

◆ DEF_LOGGER_FILE

#define DEF_LOGGER_FILE ( path,
... )
Value:
DEF_LOGGER_HEAD_ \
static std::ofstream out{path}; \
static C_ReenterableOstream ro_{out, ##__VA_ARGS__}; \
static C_SyncLogger l_{ro_, LOGGER_USE_LOCAL_TIME_}; \
DEF_LOGGER_TAIL_(l_)
Examples
test/smoke_filelog.cpp.

Definition at line 111 of file Logger.h.

◆ DEF_LOGGER_FILES

#define DEF_LOGGER_FILES ( pathfmt,
... )
Value:
DEF_LOGGER_HEAD_ \
static C_PathFmtLogSnap snap_{LOGGER_USE_LOCAL_TIME_}; \
static C_ReenterableOstreamSnap ros_{snap_.configPath(pathfmt), ##__VA_ARGS__}; \
static C_SyncLogger l_{ros_, LOGGER_USE_LOCAL_TIME_}; \
DEF_LOGGER_TAIL_(l_)
Examples
test/smoke_timelog.cpp.

Definition at line 119 of file Logger.h.

◆ DEF_LOGGER_HEAD_

#define DEF_LOGGER_HEAD_   namespace bux { namespace user { I_SyncLog &logger() {

Definition at line 72 of file Logger.h.

◆ DEF_LOGGER_OSTREAM

#define DEF_LOGGER_OSTREAM ( out,
... )
Value:
DEF_LOGGER_HEAD_ \
static C_ReenterableOstream ro_{out, ##__VA_ARGS__}; \
static C_SyncLogger l_{ro_, LOGGER_USE_LOCAL_TIME_}; \
DEF_LOGGER_TAIL_(l_)

Definition at line 101 of file Logger.h.

◆ DEF_LOGGER_TAIL_

#define DEF_LOGGER_TAIL_ ( x)
Value:
return x; }}}
Examples
test/test_logger.cpp, and test/test_paralog.cpp.

Definition at line 73 of file Logger.h.

◆ DEF_PARA_LOGGER

#define DEF_PARA_LOGGER
Value:
namespace bux { namespace user { \
C_ParaLog g_paraLog(LOGGER_USE_LOCAL_TIME_); \
I_SyncLog &logger() { \
DEF_LOGGER_TAIL_(g_paraLog)
Examples
test/smoke_filtlog.cpp, and test/smoke_paralog.cpp.

Definition at line 136 of file Logger.h.

◆ FUNLOG

#define FUNLOG   SCOPELOG(CUR_FUNC_)

◆ FUNLOGX

#define FUNLOGX ( fmtStr,
... )
Value:
SCOPELOGX(CUR_FUNC_,fmtStr, ##__VA_ARGS__)
#define SCOPELOGX(scope, fmtStr,...)
Definition Logger.h:81
#define CUR_FUNC_
Definition XPlatform.h:9
Examples
test/smoke_cerrlog.cpp, test/smoke_coutlog.cpp, and test/smoke_filelog.cpp.

Definition at line 143 of file Logger.h.

◆ LOG

#define LOG ( ll,
fmtStr,
... )
Value:
do if (bux::C_UseLog u{bux::logger(),ll}) stamp(u,ll) <<std::format(fmtStr, ##__VA_ARGS__) <<'\n'; while(false)
I_SyncLog & logger()
Definition Logger.cpp:20
Examples
test/smoke_cerrlog.cpp, test/smoke_coutlog.cpp, test/smoke_filelog.cpp, test/smoke_filtlog.cpp, test/smoke_timelog.cpp, and test/test_paralog.cpp.

Definition at line 78 of file Logger.h.

◆ LOG_RAW

#define LOG_RAW ( fmtStr,
... )
Value:
do if (bux::C_UseLog u{bux::logger()}) *u <<std::format(fmtStr, ##__VA_ARGS__) <<'\n'; while(false)
Examples
test/smoke_cerrlog.cpp, test/test_logger.cpp, and test/test_paralog.cpp.

Definition at line 79 of file Logger.h.

◆ LOGGER_USE_LOCAL_TIME_

#define LOGGER_USE_LOCAL_TIME_   true

Valid definitions: (#define before including this header)

  • Local Time
    #define LOGGER_USE_LOCAL_TIME_ true
    #define LOGGER_USE_LOCAL_TIME_ std::chrono::get_tzdb().current_zone()
    #define LOGGER_USE_LOCAL_TIME_ std::chrono::get_tzdb().locate_zone("Asia/Taipei")
  • System Clock
    #define LOGGER_USE_LOCAL_TIME_ false
    #define LOGGER_USE_LOCAL_TIME_ nullptr
Examples
test/smoke_cerrlog.cpp, test/smoke_filelog.cpp, test/smoke_filtlog.cpp, test/smoke_paralog.cpp, and test/smoke_timelog.cpp.

Definition at line 84 of file Logger.h.

◆ SCOPELOG

#define SCOPELOG ( scope)
Value:
SCOPELOG_(__LINE__,scope)
#define SCOPELOG_(line, scope)
Definition Logger.h:70

Definition at line 80 of file Logger.h.

◆ SCOPELOG_

#define SCOPELOG_ ( line,
scope )
Value:
bux::C_EntryLog _gluePair_(_log_,line)(scope)
#define _gluePair_(x, y)
Definition Logger.h:69
Log on both declaration point and end of block scope with an unique id.
Definition Logger.h:17

Definition at line 70 of file Logger.h.

◆ SCOPELOGX

#define SCOPELOGX ( scope,
fmtStr,
... )
Value:
SCOPELOGX_(__LINE__,scope,fmtStr, ##__VA_ARGS__)
#define SCOPELOGX_(line, scope, fmtStr,...)
Definition Logger.h:71

Definition at line 81 of file Logger.h.

◆ SCOPELOGX_

#define SCOPELOGX_ ( line,
scope,
fmtStr,
... )
Value:
bux::C_EntryLog _gluePair_(_log_,line)(scope,fmtStr, ##__VA_ARGS__)

Definition at line 71 of file Logger.h.