cwLog.h/cpp : Added flags(),set_flags().
This commit is contained in:
parent
75c6959529
commit
cea07592bc
22
cwLog.cpp
22
cwLog.cpp
@ -16,6 +16,7 @@ namespace cw
|
||||
logFormatCbFunc_t fmtCbFunc;
|
||||
void* fmtCbArg;
|
||||
unsigned level;
|
||||
unsigned flags;
|
||||
} log_t;
|
||||
|
||||
|
||||
@ -84,7 +85,7 @@ cw::rc_t cw::log::msg( handle_t h, unsigned level, const char* function, const c
|
||||
int m = vsnprintf(msg,n+1,fmt,vl1);
|
||||
cwAssert(m==n);
|
||||
|
||||
p->fmtCbFunc( p->fmtCbArg, p->outCbFunc, p->outCbArg, level, function, filename, line, systemErrorCode, rc, msg );
|
||||
p->fmtCbFunc( p->fmtCbArg, p->outCbFunc, p->outCbArg, p->flags, level, function, filename, line, systemErrorCode, rc, msg );
|
||||
}
|
||||
|
||||
va_end(vl1);
|
||||
@ -113,6 +114,19 @@ unsigned cw::log::level( handle_t h )
|
||||
return p->level;
|
||||
}
|
||||
|
||||
void cw::log::set_flags( handle_t h, unsigned flags )
|
||||
{
|
||||
log_t* p = _handleToPtr(h);
|
||||
p->flags = flags;
|
||||
}
|
||||
|
||||
unsigned cw::log::flags( handle_t h )
|
||||
{
|
||||
log_t* p = _handleToPtr(h);
|
||||
return p->flags;
|
||||
}
|
||||
|
||||
|
||||
void cw::log::setOutputCb( handle_t h, logOutputCbFunc_t outFunc, void* outCbArg )
|
||||
{
|
||||
log_t* p = _handleToPtr(h);
|
||||
@ -147,7 +161,7 @@ void cw::log::defaultOutput( void* arg, unsigned level, const char* text )
|
||||
fflush(f);
|
||||
}
|
||||
|
||||
void cw::log::defaultFormatter( void* cbArg, logOutputCbFunc_t outFunc, void* outCbArg, unsigned level, const char* function, const char* filename, unsigned lineno, int sys_errno, rc_t rc, const char* msg )
|
||||
void cw::log::defaultFormatter( void* cbArg, logOutputCbFunc_t outFunc, void* outCbArg, unsigned flags, unsigned level, const char* function, const char* filename, unsigned lineno, int sys_errno, rc_t rc, const char* msg )
|
||||
{
|
||||
// TODO: This code is avoids the use of dynamic memory allocation but relies on stack allocation. It's a security vulnerability.
|
||||
//
|
||||
@ -179,7 +193,9 @@ void cw::log::defaultFormatter( void* cbArg, logOutputCbFunc_t outFunc, void* ou
|
||||
|
||||
int tdn = 256;
|
||||
char td[tdn];
|
||||
time::formatDateTime( td, (unsigned)tdn );
|
||||
td[0] = 0;
|
||||
if( cwIsFlag(flags,kDateTimeFl) )
|
||||
time::formatDateTime( td, (unsigned)tdn );
|
||||
tdn = strlen(td);
|
||||
|
||||
|
||||
|
11
cwLog.h
11
cwLog.h
@ -17,10 +17,14 @@ namespace cw
|
||||
kFatal_LogLevel,
|
||||
} logLevelId_t;
|
||||
|
||||
enum {
|
||||
kDateTimeFl = 0x01,
|
||||
};
|
||||
|
||||
typedef handle<struct log_str> handle_t;
|
||||
|
||||
typedef void (*logOutputCbFunc_t)( void* cbArg, unsigned level, const char* text );
|
||||
typedef void (*logFormatCbFunc_t)( void* cbArg, logOutputCbFunc_t outFunc, void* outCbArg, unsigned level, const char* function, const char* filename, unsigned line, int systemErrorCode, rc_t rc, const char* msg );
|
||||
typedef void (*logFormatCbFunc_t)( void* cbArg, logOutputCbFunc_t outFunc, void* outCbArg, unsigned flags, unsigned level, const char* function, const char* filename, unsigned line, int systemErrorCode, rc_t rc, const char* msg );
|
||||
|
||||
rc_t create( handle_t& hRef, unsigned level=kDebug_LogLevel, logOutputCbFunc_t outCb=nullptr, void* outCbArg=nullptr, logFormatCbFunc_t fmtCb=nullptr, void* fmtCbArg=nullptr );
|
||||
rc_t destroy( handle_t& hRef );
|
||||
@ -35,9 +39,12 @@ namespace cw
|
||||
void setFormatCb( handle_t h, logFormatCbFunc_t fmtFunc, void* fmtCbArg );
|
||||
|
||||
const char* levelToLabel( unsigned level );
|
||||
|
||||
unsigned flags( handle_t h );
|
||||
void set_flags( handle_t h, unsigned flags );
|
||||
|
||||
void defaultOutput( void* arg, unsigned level, const char* text );
|
||||
void defaultFormatter( void* cbArg, logOutputCbFunc_t outFunc, void* outCbArg, unsigned level, const char* function, const char* filename, unsigned line, int systemErrorCode, rc_t rc, const char* msg );
|
||||
void defaultFormatter( void* cbArg, logOutputCbFunc_t outFunc, void* outCbArg, unsigned flags, unsigned level, const char* function, const char* filename, unsigned line, int systemErrorCode, rc_t rc, const char* msg );
|
||||
|
||||
rc_t createGlobal( unsigned level=kDebug_LogLevel, logOutputCbFunc_t outCb=nullptr, void* outCbArg=nullptr, logFormatCbFunc_t fmtCb=nullptr, void* fmtCbArg=nullptr );
|
||||
rc_t destroyGlobal( );
|
||||
|
Loading…
Reference in New Issue
Block a user