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:
Johan Wikman 2015-09-08 15:02:42 +03:00
parent 5350a85e2b
commit b84dbd8d3f
2 changed files with 64 additions and 6 deletions

View File

@ -103,6 +103,12 @@ static bool flushall_flag;
static bool flushall_started_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 */
struct filewriter_st {
#if defined(SS_DEBUG)
@ -1359,6 +1365,16 @@ 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.
*
@ -1386,16 +1402,41 @@ static int log_write(logfile_id_t id,
{
CHK_LOGMANAGER(lm);
const char format[] = "%s [%s]";
len += sizeof(format); // A bit too much, but won't hurt.
assert(function);
len += strlen(function);
const char* format;
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);
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.
char message[len];
len = snprintf(message, sizeof(message), format, str, function);
assert(len > 0);
if (log_augmentation == LOG_AUGMENT_WITH_FUNCTION)
{
len = snprintf(message, sizeof(message), format, str, function);
}
else
{
len = snprintf(message, sizeof(message), format, str);
}
assert(len >= 0);
int attempts = 0;
int successes = 0;

View File

@ -108,6 +108,15 @@ typedef struct log_info_st
*/
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
bool skygw_logmanager_init(int argc, char* argv[]);
@ -140,6 +149,14 @@ void logmanager_enable_maxscalelog(int);
#define skygw_log_write_flush(id, format, ...)\
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
const char* get_trace_prefix_default(void);