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;