Feature #835 » logCode.diff
| CMakeLists.txt | ||
|---|---|---|
| 42 | 42 |
set( USE_LEPTO 1 PARENT_SCOPE ) |
| 43 | 43 |
endif() |
| 44 | 44 | |
| 45 |
find_package( ConfigHash REQUIRED ) |
|
| 45 |
# find_package( ConfigHash REQUIRED )
|
|
| 46 | 46 | |
| 47 | 47 |
set( |
| 48 | 48 |
headers |
| ... | ... | |
| 109 | 109 |
set ( LEPTO_CONFIG_HEADER "${COMMON_CONFIG_HEADER}" )
|
| 110 | 110 |
elseif( EXISTS "${CMAKE_SYSROOT}/usr/include/lepto/config.h" )
|
| 111 | 111 |
set ( LEPTO_CONFIG_HEADER "${CMAKE_SYSROOT}/usr/include/lepto/config.h" )
|
| 112 |
else() |
|
| 113 |
set ( LEPTO_CONFIG_HEADER "${CMAKE_SOURCE_DIR}/include/lepto/presets/config_full.h" )
|
|
| 112 | 114 |
endif() |
| 113 | 115 | |
| 114 |
if( NOT ${COMMON_CONFIG_HEADER_INCLUDED} )
|
|
| 116 |
# message( FATAL_ERROR "LEPTO_CONFIG_HEADER: ${LEPTO_CONFIG_HEADER}" )
|
|
| 117 |
# message( FATAL_ERROR "COMMON_CONFIG_HEADER_INCLUDED: '${COMMON_CONFIG_HEADER_INCLUDED}'" )
|
|
| 118 | ||
| 119 |
if( NOT COMMON_CONFIG_HEADER_INCLUDED ) |
|
| 120 |
# message( FATAL_ERROR "A" ) |
|
| 115 | 121 |
if( LEPTO_CONFIG_HEADER ) |
| 116 | 122 |
get_filename_component( LEPTO_CONFIG_PATH ${LEPTO_CONFIG_HEADER} DIRECTORY )
|
| 117 | 123 |
get_filename_component( LEPTO_CONFIG_FILE ${LEPTO_CONFIG_HEADER} NAME )
|
| ... | ... | |
| 141 | 147 |
"root cmake file. If you are sure that you don't need it, set " |
| 142 | 148 |
"'LEPTO_CONFIGURED' cmake variable") |
| 143 | 149 |
endif() |
| 150 |
else() |
|
| 151 |
message( FATAL_ERROR "B" ) |
|
| 144 | 152 |
endif() |
| 145 | 153 | |
| 146 | 154 | |
| include/lepto/log.h | ||
|---|---|---|
| 27 | 27 |
#include <stdarg.h> |
| 28 | 28 |
#include <lepto/lepto.h> // IS_ENABLED( ) |
| 29 | 29 |
#include <stdlib.h> // abort() |
| 30 |
#include <lepto/logCodes.h> |
|
| 30 | 31 | |
| 31 | 32 | |
| 32 | 33 |
/*--- Implementation -------------------------------------------------------*/ |
| ... | ... | |
| 76 | 77 |
Debug = 0, |
| 77 | 78 |
Good = 0, |
| 78 | 79 |
Info = 0, |
| 79 |
Event = 1, // Device-to-device logic via log codes. E.g. "I want to shut down" |
|
| 80 |
Caution = 1, |
|
| 81 |
Warning = 2, |
|
| 82 |
Critical = 3, |
|
| 83 |
Fatal = 4, |
|
| 80 |
Gone = 1, |
|
| 81 |
Event = 2, // Device-to-device logic via log codes. E.g. "I want to shut down" |
|
| 82 |
Caution = 2, |
|
| 83 |
Warning = 3, |
|
| 84 |
Critical = 4, |
|
| 85 |
Fatal = 5, |
|
| 84 | 86 | |
| 85 | 87 |
Function = 8, // Function area |
| 86 | 88 |
Beckon = 8, // |
| ... | ... | |
| 89 | 91 |
}; |
| 90 | 92 | |
| 91 | 93 |
// The ELogCode allways contains the cathegory |
| 94 |
#if 0 |
|
| 92 | 95 |
enum class ELogCode: int; |
| 93 | 96 | |
| 94 | 97 |
inline constexpr ELogCode operator| (ELogCategory cat, int i) |
| ... | ... | |
| 96 | 99 |
//return( (ELogBlended)( (int) cat | ( i << 4 ) ) ); |
| 97 | 100 |
return( (ELogCode)( (int) cat | ( i ) ) ); |
| 98 | 101 |
} |
| 99 | ||
| 102 |
#endif |
|
| 100 | 103 |
/* |
| 101 | 104 |
inline constexpr operator ELogBlended(ELogCategory cat) |
| 102 | 105 |
{
|
| ... | ... | |
| 104 | 107 |
} |
| 105 | 108 |
*/ |
| 106 | 109 | |
| 110 |
#if 0 |
|
| 107 | 111 |
inline constexpr ELogCategory toCategory(ELogCode code) |
| 108 | 112 |
{
|
| 109 | 113 |
return( (ELogCategory)( (int) code & 0xF ) ); |
| 110 | 114 |
} |
| 111 | ||
| 115 |
#endif |
|
| 112 | 116 | |
| 113 | 117 |
#if ! IS_ENABLED( CONFIG_LEPTO_LOG_SILENT ) |
| 114 |
#define lDebugReal(msg, ...) lLog(ELogCategory::Debug|0, msg, ##__VA_ARGS__ ) |
|
| 115 |
#define lInfo(msg, ...) lLog(ELogCategory::Info|0, msg, ##__VA_ARGS__ ) |
|
| 116 |
#define lCaution(msg, ... ) lLog(ELogCategory::Caution|0, msg, ##__VA_ARGS__ ) |
|
| 117 |
#define lWarning(msg, ... ) lLog(ELogCategory::Warning|0, msg, ##__VA_ARGS__ ) |
|
| 118 |
#define lCritical(msg, ... ) lLog(ELogCategory::Critical|0, msg, ##__VA_ARGS__ ) |
|
| 119 |
#if defined STM32 |
|
| 118 |
#define lDebugReal(msg, ...) lLog(ELogCategory::Debug, msg, ##__VA_ARGS__ ) |
|
| 119 |
#define lInfo(msg, ...) lLog(ELogCategory::Info, msg, ##__VA_ARGS__ ) |
|
| 120 |
#define lCaution(msg, ... ) lLog(ELogCategory::Caution, msg, ##__VA_ARGS__ ) |
|
| 121 |
#define lWarning(msg, ... ) lLog(ELogCategory::Warning, msg, ##__VA_ARGS__ ) |
|
| 122 |
#define lCritical(msg, ... ) lLog(ELogCategory::Critical, msg, ##__VA_ARGS__ ) |
|
| 123 | ||
| 124 |
#define lWarningC( code, msg, ... ) lLog(ELogCategory::Warning, "#%X " msg, code, ##__VA_ARGS__ ) |
|
| 125 |
#define lCriticalC( code, msg, ... ) lLog(ELogCategory::Critical, "#%X """ msg, code, ##__VA_ARGS__ ) |
|
| 126 | ||
| 127 |
#if defined STM32 |
|
| 120 | 128 |
#define lFatal(msg, ... ) abort(); |
| 121 | 129 |
#else |
| 122 |
#define lFatal(msg, ... ) lLog(ELogCategory::Fatal|0, msg, ##__VA_ARGS__ )
|
|
| 130 |
#define lFatal(msg, ... ) lLog(ELogCategory::Fatal, msg, ##__VA_ARGS__ ) |
|
| 123 | 131 |
#endif |
| 124 | 132 |
#define lCalm() lLog(ELogCategory::Calm|0, "" ) |
| 125 | 133 |
#else |
| ... | ... | |
| 130 | 138 |
#define lCritical(msg, ... ) lLog(ELogCategory::Critical|0, "" ) |
| 131 | 139 |
#define lFatal(msg, ... ) lLog(ELogCategory::Fatal|0, "" ) |
| 132 | 140 |
#define lCalm() lLog(ELogCategory::Calm|0, "" ) |
| 141 | ||
| 142 |
#define lWarningC(code, msg, ... ) lLog(ELogCategory::Warning|0, "" ) |
|
| 143 |
#define lCriticalC(code, msg, ... ) lLog(ELogCategory::Critical|0, "" ) |
|
| 133 | 144 |
#endif |
| 134 | 145 | |
| 135 | 146 |
// You can use the LDS macro to give two different messages depending on the |
| ... | ... | |
| 182 | 193 |
#if ! IS_ENABLED( CONFIG_LEPTO_LOG_SILENT ) |
| 183 | 194 | |
| 184 | 195 |
extern const char *categoryMessages[]; |
| 185 |
void lVLogSimple(ELogCode code, const char *format, va_list &list );
|
|
| 186 |
void lVLogPretty(const char*file, int line, ELogCode code, const char *format, va_list &list );
|
|
| 187 |
void lLogSimple(ELogCode code, const char *format, ... );
|
|
| 188 |
void lLogPretty(const char*file, int line, ELogCode code, const char *format, ... );
|
|
| 196 |
void lVLogSimple(ELogCategory code, const char *format, va_list &list );
|
|
| 197 |
void lVLogPretty(const char*file, int line, ELogCategory code, const char *format, va_list &list );
|
|
| 198 |
void lLogSimple(ELogCategory code, const char *format, ... );
|
|
| 199 |
void lLogPretty(const char*file, int line, ELogCategory code, const char *format, ... );
|
|
| 189 | 200 |
|
| 190 | 201 |
#else |
| 191 | 202 | |
| include/lepto/log_private.h | ||
|---|---|---|
| 70 | 70 |
clock_t timeStamp; |
| 71 | 71 |
#endif |
| 72 | 72 |
|
| 73 |
ELogCategory category; |
|
| 74 | ||
| 75 |
#if IS_ENABLED( CONFIG_LEPTO_LOG_CODE ) |
|
| 73 | 76 |
ELogCode code; |
| 77 |
#endif |
|
| 74 | 78 | |
| 75 | 79 |
#if IS_ENABLED( CONFIG_LEPTO_LOG_EVENTS ) |
| 76 | 80 |
//unsigned int event; |
| src/log.cpp | ||
|---|---|---|
| 77 | 77 |
#endif |
| 78 | 78 | |
| 79 | 79 |
#if IS_ENABLED( CONFIG_LEPTO_LOG_PRETTY_PRINT ) |
| 80 |
void lVLogPretty(const char*file, int line, ELogCode code, const char *format, va_list &list )
|
|
| 80 |
void lVLogPretty(const char*file, int line, ELogCategory category, const char *format, va_list &list )
|
|
| 81 | 81 |
#else |
| 82 |
void lVLogSimple(ELogCode code, const char *format, va_list &list )
|
|
| 82 |
void lVLogSimple(ELogCategory category, const char *format, va_list &list )
|
|
| 83 | 83 |
#endif |
| 84 | 84 |
{
|
| 85 | 85 |
#if ! IS_ENABLED( CONFIG_LEPTO_LOG_DIRECT_PRINT ) |
| ... | ... | |
| 114 | 114 |
le->timeStamp = clock() / 1000; |
| 115 | 115 |
#endif |
| 116 | 116 |
#endif |
| 117 |
|
|
| 118 |
#if IS_ENABLED( CONFIG_LEPTO_LOG_CALLBACK ) |
|
| 119 |
le->code=code; |
|
| 117 | ||
| 118 |
le->category=category; |
|
| 119 | ||
| 120 |
#if IS_ENABLED( CONFIG_LEPTO_LOG_CODE ) |
|
| 121 |
if( memcmp(format, "#%X ", 4) == 0 ) |
|
| 122 |
{
|
|
| 123 |
le->code=va_arg(list, int); |
|
| 124 | ||
| 125 |
// Either adjust the format string or restore the list |
|
| 126 |
//va_start(list, format); |
|
| 127 |
format+=4; |
|
| 128 |
} |
|
| 120 | 129 |
#endif |
| 121 |
|
|
| 130 | ||
| 122 | 131 |
#if ! IS_ENABLED( CONFIG_LEPTO_LOG_SILENT ) |
| 123 | 132 |
vsnprintf( &le->logString[0], CONFIG_LEPTO_LOG_MAX_STRING_LENGTH, format, list); |
| 124 | 133 |
#endif |
| 125 | 134 |
|
| 126 |
if( toCategory(code) == ELogCategory::Fatal )
|
|
| 135 |
if( category == ELogCategory::Fatal )
|
|
| 127 | 136 |
{
|
| 128 | 137 |
#if defined ( STM32 ) |
| 129 | 138 |
// Fatal means fatal. Dont even try to print anything. |
| ... | ... | |
| 150 | 159 | |
| 151 | 160 |
#if IS_ENABLED( CONFIG_LEPTO_LOG_PRETTY_PRINT ) |
| 152 | 161 | |
| 153 |
void lLogPretty( const char*file, int line, ELogCode code, const char *format, ... )
|
|
| 162 |
void lLogPretty( const char*file, int line, ELogCategory category, const char *format, ... )
|
|
| 154 | 163 |
{
|
| 155 | 164 |
va_list list; |
| 156 | 165 |
va_start(list, format); // expected-note{{Initialized va_list}}
|
| 157 |
lVLogPretty( file, line, code, format, list);
|
|
| 166 |
lVLogPretty( file, line, category, format, list);
|
|
| 158 | 167 |
return; |
| 159 | 168 |
} |
| 160 | 169 | |
| ... | ... | |
| 182 | 191 |
while( ( le = (const SLogEntry*)logs.frontEntry() ) ) |
| 183 | 192 |
{
|
| 184 | 193 |
// Dont crash due to missing category string. Text is empty anyways. |
| 185 |
if( (int)toCategory(le->code) < (int)ELogCategory::Function )
|
|
| 194 |
if( (int)le->category < (int)ELogCategory::Function )
|
|
| 186 | 195 |
{
|
| 187 | 196 |
#if IS_ENABLED( CONFIG_LEPTO_LOG_PRETTY_PRINT ) |
| 188 | 197 |
logPrintPretty(le); |
| ... | ... | |
| 203 | 212 |
if(logOverflow) |
| 204 | 213 |
{
|
| 205 | 214 |
logOverflow=false; |
| 206 |
lCritical( "LOF" );
|
|
| 215 |
lCriticalC( LC_LOG_OVERFLOW, LDS( "LOF", "Log overflow" ) );
|
|
| 207 | 216 |
} |
| 208 | 217 | |
| 209 | 218 |
#endif // ? ! CONFIG_LEPTO_LOG_DIRECT_PRINT |
| src/logPrinter.cpp | ||
|---|---|---|
| 66 | 66 |
{ [(int)ELogCategory::Debug]="",
|
| 67 | 67 |
//[(int)ELogCategory::Caution]="", |
| 68 | 68 |
//[(int)ELogCategory::Info]="", |
| 69 |
[(int)ELogCategory::Gone]=ANSI_GREEN "Gone: ", |
|
| 69 | 70 |
[(int)ELogCategory::Caution]=ANSI_YELLOW "Caution: ", |
| 70 | 71 |
[(int)ELogCategory::Warning]=ANSI_ORANGE "Warning: ", |
| 71 | 72 |
[(int)ELogCategory::Critical]=ANSI_RED "Error: ", |
| 72 | 73 |
[(int)ELogCategory::Fatal]=ANSI_RED "Fatal: " }; |
| 73 | 74 |
#else |
| 74 | 75 |
{ [ (int)ELogCategory::Debug ]="",
|
| 76 |
[(int)ELogCategory::Gone ]="G:", |
|
| 75 | 77 |
[(int)ELogCategory::Caution ]="C:", |
| 76 | 78 |
[(int)ELogCategory::Warning ]="W:", |
| 77 | 79 |
[(int)ELogCategory::Critical ]="E:", |
| ... | ... | |
| 105 | 107 |
fputs(".", stdout);
|
| 106 | 108 |
} |
| 107 | 109 |
fputs( ": ", stdout ); |
| 108 |
fputs( categoryMessages[ (int)toCategory(le->code) ], stdout );
|
|
| 110 |
fputs( categoryMessages[ (int)le->category ], stdout );
|
|
| 109 | 111 |
fputs( ANSI_NORMAL, stdout ); |
| 110 | 112 |
fputs( le->logString, stdout ); |
| 111 | 113 |
fputs( "\n", stdout ); |
| tests/test_log.cpp | ||
|---|---|---|
| 40 | 40 |
SECTION( "Output" ) |
| 41 | 41 |
{
|
| 42 | 42 |
lWarning( "BOF: %d", 10 ); |
| 43 |
lLog( ELogCategory::Warning | EV_BOF, "E-BOF: %d", 10 );
|
|
| 43 |
lLog( ELogCategory::Warning, "E-BOF: %d", 10 ); |
|
| 44 | 44 |
} |
| 45 | 45 |
} |
| 46 | 46 | |