Skip to content

Commit 726c080

Browse files
committed
Add configure options for logging
1 parent 5b868dc commit 726c080

File tree

5 files changed

+94
-6
lines changed

5 files changed

+94
-6
lines changed

configure.c

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
#include "pg_probackup.h"
1111

12+
static void opt_log_level(pgut_option *opt, const char *arg);
13+
14+
static pgBackupConfig *cur_config = NULL;
15+
1216
/* Set configure options */
1317
int
1418
do_configure(bool show_only)
@@ -25,6 +29,19 @@ do_configure(bool show_only)
2529
if (username)
2630
config->pguser = username;
2731

32+
if (log_level_defined)
33+
config->log_level = log_level;
34+
if (log_filename)
35+
config->log_filename = log_filename;
36+
if (error_log_filename)
37+
config->error_log_filename = error_log_filename;
38+
if (log_directory)
39+
config->log_directory = log_directory;
40+
if (log_rotation_size)
41+
config->log_rotation_size = log_rotation_size;
42+
if (log_rotation_age)
43+
config->log_rotation_age = log_rotation_age;
44+
2845
if (retention_redundancy)
2946
config->retention_redundancy = retention_redundancy;
3047
if (retention_window)
@@ -48,6 +65,13 @@ pgBackupConfigInit(pgBackupConfig *config)
4865
config->pgport = NULL;
4966
config->pguser = NULL;
5067

68+
config->log_level = INT_MIN; // INT_MIN means "undefined"
69+
config->log_filename = NULL;
70+
config->error_log_filename = NULL;
71+
config->log_directory = NULL;
72+
config->log_rotation_size = 0;
73+
config->log_rotation_age = 0;
74+
5175
config->retention_redundancy = 0;
5276
config->retention_window = 0;
5377
}
@@ -69,6 +93,20 @@ writeBackupCatalogConfig(FILE *out, pgBackupConfig *config)
6993
if (config->pguser)
7094
fprintf(out, "PGUSER = %s\n", config->pguser);
7195

96+
fprintf(out, "#Logging parameters:\n");
97+
if (config->log_level != INT_MIN)
98+
fprintf(out, "log-level = %s\n", deparse_log_level(config->log_level));
99+
if (config->log_filename)
100+
fprintf(out, "log-filename = %s\n", config->log_filename);
101+
if (config->error_log_filename)
102+
fprintf(out, "error-log-filename = %s\n", config->error_log_filename);
103+
if (config->log_directory)
104+
fprintf(out, "log-directory = %s\n", config->log_directory);
105+
if (config->log_rotation_size)
106+
fprintf(out, "log-rotation-size = %d\n", config->log_rotation_size);
107+
if (config->log_rotation_age)
108+
fprintf(out, "log-rotation-age = %d\n", config->log_rotation_age);
109+
72110
fprintf(out, "#Retention parameters:\n");
73111
if (config->retention_redundancy)
74112
fprintf(out, "retention-redundancy = %u\n", config->retention_redundancy);
@@ -107,12 +145,12 @@ readBackupCatalogConfigFile(void)
107145
{ 'u', 0, "retention-redundancy", &(config->retention_redundancy),SOURCE_FILE_STRICT },
108146
{ 'u', 0, "retention-window", &(config->retention_window), SOURCE_FILE_STRICT },
109147
/* logging options */
110-
// { 'f', 40, "log-level", opt_log_level, SOURCE_CMDLINE },
111-
// { 's', 41, "log-filename", &log_filename, SOURCE_CMDLINE },
112-
// { 's', 42, "error-log-filename", &error_log_filename, SOURCE_CMDLINE },
113-
// { 's', 43, "log-directory", &log_directory, SOURCE_CMDLINE },
114-
// { 'u', 44, "log-rotation-size", &log_rotation_size, SOURCE_CMDLINE },
115-
// { 'u', 45, "log-rotation-age", &log_rotation_age, SOURCE_CMDLINE },
148+
{ 'f', 40, "log-level", opt_log_level, SOURCE_CMDLINE },
149+
{ 's', 41, "log-filename", &(config->log_filename), SOURCE_CMDLINE },
150+
{ 's', 42, "error-log-filename", &(config->error_log_filename), SOURCE_CMDLINE },
151+
{ 's', 43, "log-directory", &(config->log_directory), SOURCE_CMDLINE },
152+
{ 'u', 44, "log-rotation-size", &(config->log_rotation_size), SOURCE_CMDLINE },
153+
{ 'u', 45, "log-rotation-age", &(config->log_rotation_age), SOURCE_CMDLINE },
116154
/* connection options */
117155
{ 's', 0, "pgdata", &(config->pgdata), SOURCE_FILE_STRICT },
118156
{ 's', 0, "pgdatabase", &(config->pgdatabase), SOURCE_FILE_STRICT },
@@ -124,6 +162,8 @@ readBackupCatalogConfigFile(void)
124162
{0}
125163
};
126164

165+
cur_config = config;
166+
127167
join_path_components(path, backup_path, BACKUPS_DIR);
128168
join_path_components(path, backup_path, BACKUP_CATALOG_CONF_FILE);
129169

@@ -133,3 +173,9 @@ readBackupCatalogConfigFile(void)
133173
return config;
134174

135175
}
176+
177+
static void
178+
opt_log_level(pgut_option *opt, const char *arg)
179+
{
180+
cur_config->log_level = parse_log_level(arg);
181+
}

pg_probackup.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,5 @@ static void
312312
opt_log_level(pgut_option *opt, const char *arg)
313313
{
314314
log_level = parse_log_level(arg);
315+
log_level_defined = true;
315316
}

pg_probackup.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ typedef struct pgBackupConfig
127127
const char *pgport;
128128
const char *pguser;
129129

130+
int log_level;
131+
char *log_filename;
132+
char *error_log_filename;
133+
char *log_directory;
134+
int log_rotation_size;
135+
int log_rotation_age;
136+
130137
uint32 retention_redundancy;
131138
uint32 retention_window;
132139
} pgBackupConfig;

utils/logger.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/* Logger parameters */
2121

2222
int log_level = INFO;
23+
bool log_level_defined = false;
2324

2425
char *log_filename = NULL;
2526
char *error_log_filename = NULL;
@@ -288,6 +289,37 @@ parse_log_level(const char *level)
288289
return 0;
289290
}
290291

292+
/*
293+
* Converts integer representation of log level to string.
294+
*/
295+
const char *
296+
deparse_log_level(int level)
297+
{
298+
switch (level)
299+
{
300+
case VERBOSE:
301+
return "VERBOSE";
302+
case LOG:
303+
return "LOG";
304+
case INFO:
305+
return "INFO";
306+
case NOTICE:
307+
return "NOTICE";
308+
case WARNING:
309+
return "WARNING";
310+
case ERROR:
311+
return "ERROR";
312+
case FATAL:
313+
return "FATAL";
314+
case PANIC:
315+
return "PANIC";
316+
default:
317+
elog(ERROR, "invalid log-level %d", level);
318+
}
319+
320+
return NULL;
321+
}
322+
291323
/*
292324
* Construct logfile name using timestamp information.
293325
*

utils/logger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
/* Logger parameters */
2626

2727
extern int log_level;
28+
extern bool log_level_defined;
2829

2930
extern char *log_filename;
3031
extern char *error_log_filename;
@@ -38,5 +39,6 @@ extern int log_rotation_age;
3839
extern void elog(int elevel, const char *fmt, ...) pg_attribute_printf(2, 3);
3940

4041
extern int parse_log_level(const char *level);
42+
extern const char *deparse_log_level(int level);
4143

4244
#endif /* LOGGER_H */

0 commit comments

Comments
 (0)