MXS-362: Enable/disable log augmentation

Log message augmentation (appending of function name) can now
be enabled or disabled via the configuration file and command
line.

By default, the augmentation is disabled.
This commit is contained in:
Johan Wikman
2015-09-11 15:21:31 +03:00
parent 535523f9d7
commit 37f8148574
4 changed files with 39 additions and 2 deletions

View File

@ -124,6 +124,18 @@ log_debug=1
To disable the log use the value 0 and to enable it use the value 1.
#### `log_augmentation`
Enable or disable the augmentation of messages. If this is enabled, then each logged message is appended with the name of the function where the message was logged. This is primarily for development purposes and hence is disabled by default.
```
# Valid options are:
# log_augmentation=<0|1>
log_augmentation=1
```
To disable the augmentation use the value 0 and to enable it use the value 1.
#### `logdir`
Set the directory where the logfiles are stored. The folder needs to be both readable and writable by the user running MaxScale.

View File

@ -43,6 +43,7 @@ Switch|Long Option|Description
`-U USER`|`--user=USER`|run MaxScale as another user. The user ID and group ID of this user are used to run MaxScale.
`-s [yes no]`|`--syslog=[yes no]`|log messages to syslog (default:yes)
`-S [yes no]`|`--maxscalelog=[yes no]`|log messages to MaxScale log (default: yes)
`-G [0 1]`|`--log_augmentation=[0 1]`|augment messages with the name of the function where the message was logged (default: 0). Primarily for development purposes.
`-v`|`--version`|print version info and exit
`-V`|`--version-full`|print version info and the commit ID the binary was built from
`-?`|`--help`|show this help

View File

@ -106,7 +106,7 @@ static bool flushall_done_flag;
/**
* Default augmentation.
*/
static int default_log_augmentation = LOG_AUGMENT_WITH_FUNCTION;
static int default_log_augmentation = 0;
static int log_augmentation = default_log_augmentation;
/** Writer thread structure */

View File

@ -181,6 +181,7 @@ static struct option long_options[] = {
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, '?'},
{"version-full", no_argument, 0, 'V'},
{"log_augmentation", required_argument, 0, 'G'},
{0, 0, 0, 0}
};
static int cnf_preparser(void* data, const char* section, const char* name, const char* value);
@ -197,6 +198,7 @@ static int ntfw_cb(const char*, const struct stat*, int, struct FTW*);
static bool file_is_readable(char* absolute_pathname);
static bool file_is_writable(char* absolute_pathname);
bool handle_path_arg(char** dest, char* path, char* arg, bool rd, bool wr);
static void set_log_augmentation(const char* value);
static void usage(void);
static char* get_expanded_pathname(
char** abs_path,
@ -1128,7 +1130,7 @@ int main(int argc, char **argv)
}
}
while ((opt = getopt_long(argc, argv, "dc:f:l:vVs:S:?L:D:C:B:U:A:P:",
while ((opt = getopt_long(argc, argv, "dc:f:l:vVs:S:?L:D:C:B:U:A:P:G:",
long_options, &option_index)) != -1)
{
bool succp = true;
@ -1291,6 +1293,9 @@ int main(int argc, char **argv)
succp = false;
}
break;
case 'G':
set_log_augmentation(optarg);
break;
case '?':
usage();
rc = EXIT_SUCCESS;
@ -2312,6 +2317,21 @@ bool handle_path_arg(char** dest, char* path, char* arg, bool rd, bool wr)
return rval;
}
void set_log_augmentation(const char* value)
{
// Command line arguments are handled first, thus command line argument
// has priority.
static bool augmentation_set = false;
if (!augmentation_set)
{
skygw_log_set_augmentation(atoi(value));
augmentation_set = true;
}
}
/**
* Pre-parse the MaxScale.cnf for config, log and module directories.
* @param data Parameter passed by inih
@ -2423,6 +2443,10 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons
{
cnf->maxlog = config_truth_value((char*)value);
}
else if(strcmp(name, "log_augmentation") == 0)
{
set_log_augmentation(value);
}
}
return 1;