pgpro-2065. fix logging for checkdb command

This commit is contained in:
Anastasia
2018-12-11 17:37:52 +03:00
parent 350422afe8
commit 5f404b5de4
2 changed files with 17 additions and 7 deletions
+8 -2
View File
@@ -395,9 +395,15 @@ main(int argc, char *argv[])
if (backup_path == NULL && backup_subcmd == CHECKDB_CMD)
config_get_opt_env(instance_options);
if (backup_subcmd == CHECKDB_CMD
&& (&instance_config.logger.log_level_file != LOG_OFF)
&& (&instance_config.logger.log_directory == NULL))
elog(ERROR, "Cannot save checkdb logs to a file. "
"You must specify --log-directory option when running checkdb with "
"--log-level-file option enabled.");
/* Initialize logger */
if (backup_subcmd != CHECKDB_CMD)
init_logger(backup_path, &instance_config.logger);
init_logger(backup_path, &instance_config.logger);
/* command was initialized for a few commands */
if (command)
+9 -5
View File
@@ -71,12 +71,16 @@ static pthread_mutex_t log_file_mutex = PTHREAD_MUTEX_INITIALIZER;
void
init_logger(const char *root_path, LoggerConfig *config)
{
/* Set log path */
if (config->log_directory == NULL)
/*
* If logging to file is enabled and log_directory wasn't set
* by user, init the path with default value: backup_directory/log/
* */
if (config->log_level_file != LOG_OFF
&& config->log_directory == NULL)
{
config->log_directory = pgut_malloc(MAXPGPATH);
join_path_components(config->log_directory,
root_path, LOG_DIRECTORY_DEFAULT);
config->log_directory = pgut_malloc(MAXPGPATH);
join_path_components(config->log_directory,
root_path, LOG_DIRECTORY_DEFAULT);
}
logger_config = *config;