master - logging: new config settings to specify debug fields
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=90149c303e3c0d2d09b14d218924d0bc6c91469d Commit: 90149c303e3c0d2d09b14d218924d0bc6c91469d Parent: 74460f70efca7c8ed76e5980b300668a1a328cc4 Author: David Teigland <[email protected]> AuthorDate: Tue Feb 26 14:31:44 2019 -0600 Committer: David Teigland <[email protected]> CommitterDate: Tue Feb 26 14:42:16 2019 -0600
logging: new config settings to specify debug fields
For users who do not want all of the fields included in debug lines, let them specify in lvm.conf which fields to include. timestamp, command[pid], and file:line fields can all be disabled.
--- lib/commands/toolcontext.c | 42 +++++++++++++++++++++++++++++++++ lib/config/config_settings.h | 8 ++++++ lib/log/log.c | 52 ++++++++++++++++++++++++++++++++++++----- lib/log/log.h | 7 +++++ lib/log/lvm-logging.h | 3 ++ 5 files changed, 105 insertions(+), 7 deletions(-)
lib/commands/toolcontext.c +42 -0
@@ -232,6 +232,45 @@ static void _get_sysfs_dir(struct cmd_context *cmd, char *buf, size_t buf_size)strncpy (buf, sys_mnt, buf_size); } +static uint32_t _parse_debug_fields (struct cmd_context *cmd,int cfg,const char *cfgname) +{ +const struct dm_config_node *cn; +const struct dm_config_value *cv; +uint32_t debug_fields =0 ; + +if (!(cn =find_config_tree_array (cmd, cfg,NULL ))) { +log_error (INTERNAL_ERROR "Unable to find configuration for log/%s." , cfgname); +return 0 ; + } + +for (cv = cn->v; cv; cv = cv->next) { +if (cv->type !=DM_CFG_STRING ) { +log_verbose ("log/%s contains a value which is not a string. Ignoring." , cfgname); +continue ; + } + +if (!strcasecmp (cv->v.str,"all" )) +return 0 ; + +if (!strcasecmp (cv->v.str,"time" )) + debug_fields |=LOG_DEBUG_FIELD_TIME ; + +else if (!strcasecmp (cv->v.str,"command" )) + debug_fields |=LOG_DEBUG_FIELD_COMMAND ; + +else if (!strcasecmp (cv->v.str,"fileline" )) + debug_fields |=LOG_DEBUG_FIELD_FILELINE ; + +else if (!strcasecmp (cv->v.str,"message" )) + debug_fields |=LOG_DEBUG_FIELD_MESSAGE ; + +else +log_verbose ("Unrecognised value for log/%s: %s" , cfgname, cv->v.str); + } + +return debug_fields; +} +static int _parse_debug_classes (struct cmd_context *cmd) {const struct dm_config_node *cn;
@@ -350,6 +389,9 @@ static void _init_logging(struct cmd_context *cmd)log_debug ("Setting log debug classes to %d" , cmd->default_settings.debug_classes);init_debug_classes_logged (cmd->default_settings.debug_classes); +init_debug_file_fields (_parse_debug_fields (cmd, log_debug_file_fields_CFG,"debug_file_fields" )); +init_debug_output_fields (_parse_debug_fields (cmd, log_debug_output_fields_CFG,"debug_output_fields" )); + t =time (NULL );ctime_r (&t, &timebuf[0 ]); timebuf[24 ] ='\0' ;
lib/config/config_settings.h +8 -0
@@ -838,6 +838,14 @@ cfg_array(log_debug_classes_CFG, "debug_classes", log_CFG_SECTION, CFG_ALLOW_EMP "available: memory, devices, io, activation, allocation,\n" "metadata, cache, locking, lvmpolld. Use \"all\" to see everything.\n") +cfg_array(log_debug_file_fields_CFG, "debug_file_fields", log_CFG_SECTION, CFG_DEFAULT_COMMENTED | CFG_ADVANCED, CFG_TYPE_STRING, "#Stime#Scommand#Sfileline#Smessage", vsn(2, 3, 2), NULL, 0, NULL, + "The fields included in debug output written to log file.\n" + "Use \"all\" to include everything (the default).\n") + +cfg_array(log_debug_output_fields_CFG, "debug_output_fields", log_CFG_SECTION, CFG_DEFAULT_COMMENTED | CFG_ADVANCED, CFG_TYPE_STRING, "#Stime#Scommand#Sfileline#Smessage", vsn(2, 3, 2), NULL, 0, NULL, + "The fields included in debug output written to stderr.\n" + "Use \"all\" to include everything (the default).\n") +cfg (backup_backup_CFG,"backup" , backup_CFG_SECTION,0 ,CFG_TYPE_BOOL ,DEFAULT_BACKUP_ENABLED ,vsn (1 ,0 ,0 ),NULL ,0 ,NULL ,"Maintain a backup of the current metadata configuration.\n" "Think very hard before turning this off!\n" )
lib/log/log.c +45 -7
85 lines not on this page · raw message
lib/log/log.h +7 -0
@@ -57,6 +57,13 @@#define INTERNAL_ERROR "Internal error: " +#define LOG_DEBUG_FIELD_ALL 0x0000 +#define LOG_DEBUG_FIELD_TIME 0x0001 +#define LOG_DEBUG_FIELD_COMMAND 0x0002 +#define LOG_DEBUG_FIELD_FILELINE 0x0004 +#define LOG_DEBUG_FIELD_MESSAGE 0x0008 + +/* * Classes available for debug log messages. * These are also listed in doc/example.conf
lib/log/lvm-logging.h +3 -0
@@ -48,6 +48,9 @@ void init_log_fn(lvm2_log_fn_t log_fn);void init_indent (int indent);void init_msg_prefix (const char *prefix); +void init_debug_file_fields (uint32_t debug_fields); +void init_debug_output_fields (uint32_t debug_fields); +void init_log_file (const char *log_file,int append);void unlink_log_file (int ret);void init_log_direct (const char *log_file,int append);