MXS-357: Possibility to turn off log message augmentation.
It's not always desireable to have the function name appended to every logged line.
This commit is contained in:
@ -103,6 +103,12 @@ static bool flushall_flag;
|
|||||||
static bool flushall_started_flag;
|
static bool flushall_started_flag;
|
||||||
static bool flushall_done_flag;
|
static bool flushall_done_flag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default augmentation.
|
||||||
|
*/
|
||||||
|
static int default_log_augmentation = LOG_AUGMENT_WITH_FUNCTION;
|
||||||
|
static int log_augmentation = default_log_augmentation;
|
||||||
|
|
||||||
/** Writer thread structure */
|
/** Writer thread structure */
|
||||||
struct filewriter_st {
|
struct filewriter_st {
|
||||||
#if defined(SS_DEBUG)
|
#if defined(SS_DEBUG)
|
||||||
@ -1359,6 +1365,16 @@ return_succp:
|
|||||||
return succp;
|
return succp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void skygw_log_set_augmentation(int bits)
|
||||||
|
{
|
||||||
|
log_augmentation = bits & LOG_AUGMENTATION_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int skygw_log_get_augmentation()
|
||||||
|
{
|
||||||
|
return log_augmentation;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for skygw_log_write and friends.
|
* Helper for skygw_log_write and friends.
|
||||||
*
|
*
|
||||||
@ -1386,16 +1402,41 @@ static int log_write(logfile_id_t id,
|
|||||||
{
|
{
|
||||||
CHK_LOGMANAGER(lm);
|
CHK_LOGMANAGER(lm);
|
||||||
|
|
||||||
const char format[] = "%s [%s]";
|
const char* format;
|
||||||
len += sizeof(format); // A bit too much, but won't hurt.
|
|
||||||
|
if (log_augmentation == LOG_AUGMENT_WITH_FUNCTION)
|
||||||
|
{
|
||||||
|
static const char function_format[] = "%s [%s]";
|
||||||
|
|
||||||
|
format = function_format;
|
||||||
|
|
||||||
|
len += sizeof(function_format); // A little bit more than needed, but won't hurt.
|
||||||
assert(function);
|
assert(function);
|
||||||
len += strlen(function);
|
len += strlen(function);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
static const char default_format[] = "%s";
|
||||||
|
|
||||||
|
format = default_format;
|
||||||
|
|
||||||
|
len += sizeof(default_format); // A little bit more than needed, but won't hurt.
|
||||||
|
}
|
||||||
|
|
||||||
len += 1; // For the trailing NULL.
|
len += 1; // For the trailing NULL.
|
||||||
|
|
||||||
char message[len];
|
char message[len];
|
||||||
|
|
||||||
|
if (log_augmentation == LOG_AUGMENT_WITH_FUNCTION)
|
||||||
|
{
|
||||||
len = snprintf(message, sizeof(message), format, str, function);
|
len = snprintf(message, sizeof(message), format, str, function);
|
||||||
assert(len > 0);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
len = snprintf(message, sizeof(message), format, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(len >= 0);
|
||||||
|
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
int successes = 0;
|
int successes = 0;
|
||||||
|
|||||||
@ -108,6 +108,15 @@ typedef struct log_info_st
|
|||||||
*/
|
*/
|
||||||
typedef enum { UNINIT = 0, INIT, RUN, DONE } flat_obj_state_t;
|
typedef enum { UNINIT = 0, INIT, RUN, DONE } flat_obj_state_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LOG_AUGMENT_WITH_FUNCTION Each logged line is suffixed with [function-name].
|
||||||
|
*/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
LOG_AUGMENT_WITH_FUNCTION = 1,
|
||||||
|
LOG_AUGMENTATION_MASK = (LOG_AUGMENT_WITH_FUNCTION)
|
||||||
|
} log_augmentation_t;
|
||||||
|
|
||||||
EXTERN_C_BLOCK_BEGIN
|
EXTERN_C_BLOCK_BEGIN
|
||||||
|
|
||||||
bool skygw_logmanager_init(int argc, char* argv[]);
|
bool skygw_logmanager_init(int argc, char* argv[]);
|
||||||
@ -140,6 +149,14 @@ void logmanager_enable_maxscalelog(int);
|
|||||||
#define skygw_log_write_flush(id, format, ...)\
|
#define skygw_log_write_flush(id, format, ...)\
|
||||||
skygw_log_write_context_flush(id, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__)
|
skygw_log_write_context_flush(id, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What augmentation if any should a logged message be augmented with.
|
||||||
|
*
|
||||||
|
* Currently this is a global setting and affects all loggers.
|
||||||
|
*/
|
||||||
|
void skygw_log_set_augmentation(int bits);
|
||||||
|
int skygw_log_get_augmentation();
|
||||||
|
|
||||||
EXTERN_C_BLOCK_END
|
EXTERN_C_BLOCK_END
|
||||||
|
|
||||||
const char* get_trace_prefix_default(void);
|
const char* get_trace_prefix_default(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user