bux API Reference 1.11.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 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 DEF_LOGGER_COUT(...)
 
#define DEF_LOGGER_CERR(...)
 
#define SCOPELOG(scope)
 
#define SCOPELOGX(scope, fmtStr, ...)
 
#define FUNLOG   SCOPELOG(CUR_FUNC_)
 
#define FUNLOGX(fmtStr, ...)
 
#define LOG1(ll, str)
 
#define SCOPELOGX1(scope, x)
 
#define SCOPELOGX2(scope, x1, x2)
 
#define SCOPELOGX3(scope, x1, x2, x3)
 
#define SCOPELOGX4(scope, x1, x2, x3, x4)
 
#define SCOPELOGX5(scope, x1, x2, x3, x4, x5)
 
#define SCOPELOGX6(scope, x1, x2, x3, x4, x5, x6)
 
#define SCOPELOGX7(scope, x1, x2, x3, x4, x5, x6, x7)
 
#define SCOPELOGX8(scope, x1, x2, x3, x4, x5, x6, x7, x8)
 
#define SCOPELOGX9(scope, x1, x2, x3, x4, x5, x6, x7, x8, x9)
 
#define FUNLOGX1(x)
 
#define FUNLOGX2(x1, x2)
 
#define FUNLOGX3(x1, x2, x3)
 
#define FUNLOGX4(x1, x2, x3, x4)
 
#define FUNLOGX5(x1, x2, x3, x4, x5)
 
#define FUNLOGX6(x1, x2, x3, x4, x5, x6)
 
#define FUNLOGX7(x1, x2, x3, x4, x5, x6, x7)
 
#define FUNLOGX8(x1, x2, x3, x4, x5, x6, x7, x8)
 
#define FUNLOGX9(x1, x2, x3, x4, x5, x6, x7, x8, x9)
 

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 65 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:80
THE common namespace of bux library.
Definition AtomiX.cpp:3
I_SyncLog & logger()
Definition Logger.cpp:20
Examples
test/smoke_timelog.cpp.

Definition at line 123 of file Logger.h.

◆ DEF_LOGGER_CERR [1/2]

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

Definition at line 104 of file Logger.h.

◆ DEF_LOGGER_CERR [2/2]

#define DEF_LOGGER_CERR ( ...)
Value:
DEF_LOGGER_OSTREAM(std::cerr, ##__VA_ARGS__)

Definition at line 104 of file Logger.h.

◆ DEF_LOGGER_COUT [1/2]

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

Definition at line 103 of file Logger.h.

◆ DEF_LOGGER_COUT [2/2]

#define DEF_LOGGER_COUT ( ...)
Value:
DEF_LOGGER_OSTREAM(std::cout, ##__VA_ARGS__)

Definition at line 103 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 107 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 115 of file Logger.h.

◆ DEF_LOGGER_HEAD_

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

Definition at line 70 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 97 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 71 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)

Definition at line 132 of file Logger.h.

◆ FUNLOG

#define FUNLOG   SCOPELOG(CUR_FUNC_)

Definition at line 155 of file Logger.h.

◆ FUNLOGX

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

Definition at line 156 of file Logger.h.

◆ FUNLOGX1

#define FUNLOGX1 ( x)
Value:
FUNLOGX("{}", x)
#define FUNLOGX(fmtStr,...)
Definition Logger.h:156
Examples
test/smoke_coutlog.cpp.

Definition at line 170 of file Logger.h.

◆ FUNLOGX2

#define FUNLOGX2 ( x1,
x2 )
Value:
FUNLOGX("{}, {}", x1, x2)
Examples
test/smoke_coutlog.cpp.

Definition at line 171 of file Logger.h.

◆ FUNLOGX3

#define FUNLOGX3 ( x1,
x2,
x3 )
Value:
FUNLOGX("{}, {}, {}", x1, x2, x3)
Examples
test/smoke_coutlog.cpp.

Definition at line 172 of file Logger.h.

◆ FUNLOGX4

#define FUNLOGX4 ( x1,
x2,
x3,
x4 )
Value:
FUNLOGX("{}, {}, {}, {}", x1, x2, x3, x4)
Examples
test/smoke_coutlog.cpp.

Definition at line 173 of file Logger.h.

◆ FUNLOGX5

#define FUNLOGX5 ( x1,
x2,
x3,
x4,
x5 )
Value:
FUNLOGX("{}, {}, {}, {}, {}", x1, x2, x3, x4, x5)
Examples
test/smoke_coutlog.cpp.

Definition at line 174 of file Logger.h.

◆ FUNLOGX6

#define FUNLOGX6 ( x1,
x2,
x3,
x4,
x5,
x6 )
Value:
FUNLOGX("{}, {}, {}, {}, {}, {}", x1, x2, x3, x4, x5, x6)
Examples
test/smoke_coutlog.cpp.

Definition at line 175 of file Logger.h.

◆ FUNLOGX7

#define FUNLOGX7 ( x1,
x2,
x3,
x4,
x5,
x6,
x7 )
Value:
FUNLOGX("{}, {}, {}, {}, {}, {}, {}", x1, x2, x3, x4, x5, x6, x7)
Examples
test/smoke_coutlog.cpp.

Definition at line 176 of file Logger.h.

◆ FUNLOGX8

#define FUNLOGX8 ( x1,
x2,
x3,
x4,
x5,
x6,
x7,
x8 )
Value:
FUNLOGX("{}, {}, {}, {}, {}, {}, {}, {}", x1, x2, x3, x4, x5, x6, x7, x8)
Examples
test/smoke_coutlog.cpp.

Definition at line 177 of file Logger.h.

◆ FUNLOGX9

#define FUNLOGX9 ( x1,
x2,
x3,
x4,
x5,
x6,
x7,
x8,
x9 )
Value:
FUNLOGX("{}, {}, {}, {}, {}, {}, {}, {}, {}", x1, x2, x3, x4, x5, x6, x7, x8, x9)
Examples
test/smoke_coutlog.cpp.

Definition at line 178 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)
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 76 of file Logger.h.

◆ LOG1

#define LOG1 ( ll,
str )
Value:
LOG(ll, "{}", str)
#define LOG(ll, fmtStr,...)
Definition Logger.h:76
Examples
test/smoke_coutlog.cpp.

Definition at line 158 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 77 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

Definition at line 80 of file Logger.h.

◆ SCOPELOG

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

Definition at line 153 of file Logger.h.

◆ SCOPELOG_

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

Definition at line 68 of file Logger.h.

◆ SCOPELOGX

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

Definition at line 154 of file Logger.h.

◆ SCOPELOGX1

#define SCOPELOGX1 ( scope,
x )
Value:
SCOPELOGX(scope, "{}", x)
Examples
test/smoke_coutlog.cpp.

Definition at line 160 of file Logger.h.

◆ SCOPELOGX2

#define SCOPELOGX2 ( scope,
x1,
x2 )
Value:
SCOPELOGX(scope, "{}, {}", x1, x2)
Examples
test/smoke_coutlog.cpp.

Definition at line 161 of file Logger.h.

◆ SCOPELOGX3

#define SCOPELOGX3 ( scope,
x1,
x2,
x3 )
Value:
SCOPELOGX(scope, "{}, {}, {}", x1, x2, x3)
Examples
test/smoke_coutlog.cpp.

Definition at line 162 of file Logger.h.

◆ SCOPELOGX4

#define SCOPELOGX4 ( scope,
x1,
x2,
x3,
x4 )
Value:
SCOPELOGX(scope, "{}, {}, {}, {}", x1, x2, x3, x4)
Examples
test/smoke_coutlog.cpp.

Definition at line 163 of file Logger.h.

◆ SCOPELOGX5

#define SCOPELOGX5 ( scope,
x1,
x2,
x3,
x4,
x5 )
Value:
SCOPELOGX(scope, "{}, {}, {}, {}, {}", x1, x2, x3, x4, x5)
Examples
test/smoke_coutlog.cpp.

Definition at line 164 of file Logger.h.

◆ SCOPELOGX6

#define SCOPELOGX6 ( scope,
x1,
x2,
x3,
x4,
x5,
x6 )
Value:
SCOPELOGX(scope, "{}, {}, {}, {}, {}, {}", x1, x2, x3, x4, x5, x6)
Examples
test/smoke_coutlog.cpp.

Definition at line 165 of file Logger.h.

◆ SCOPELOGX7

#define SCOPELOGX7 ( scope,
x1,
x2,
x3,
x4,
x5,
x6,
x7 )
Value:
SCOPELOGX(scope, "{}, {}, {}, {}, {}, {}, {}", x1, x2, x3, x4, x5, x6, x7)
Examples
test/smoke_coutlog.cpp.

Definition at line 166 of file Logger.h.

◆ SCOPELOGX8

#define SCOPELOGX8 ( scope,
x1,
x2,
x3,
x4,
x5,
x6,
x7,
x8 )
Value:
SCOPELOGX(scope, "{}, {}, {}, {}, {}, {}, {}, {}", x1, x2, x3, x4, x5, x6, x7, x8)
Examples
test/smoke_coutlog.cpp.

Definition at line 167 of file Logger.h.

◆ SCOPELOGX9

#define SCOPELOGX9 ( scope,
x1,
x2,
x3,
x4,
x5,
x6,
x7,
x8,
x9 )
Value:
SCOPELOGX(scope, "{}, {}, {}, {}, {}, {}, {}, {}, {}", x1, x2, x3, x4, x5, x6, x7, x8, x9)
Examples
test/smoke_coutlog.cpp.

Definition at line 168 of file Logger.h.

◆ SCOPELOGX_

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

Definition at line 69 of file Logger.h.