Skip to content

Commit 350b1ba

Browse files
okbob@github.comhackorum
authored andcommitted
Print opening INFO lines with coulours
By default it use inverse printing for lines: INFO: vacuuming tablename INFO: repacking tablename INFO: analyzing tablename It helps with orientation inside verbose output of REINDEX, VACUUM and ANALYZE commands.
1 parent 19733fa commit 350b1ba

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/common/logging.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ static const char *sgr_error = NULL;
3232
static const char *sgr_warning = NULL;
3333
static const char *sgr_note = NULL;
3434
static const char *sgr_locus = NULL;
35+
static const char *sgr_info_command = NULL;
3536

3637
#define SGR_ERROR_DEFAULT "01;31"
3738
#define SGR_WARNING_DEFAULT "01;35"
3839
#define SGR_NOTE_DEFAULT "01;36"
3940
#define SGR_LOCUS_DEFAULT "01"
41+
#define SGR_INFO_COMMAND_DEFAULT "07"
4042

4143
#define ANSI_ESCAPE_FMT "\x1b[%sm"
4244
#define ANSI_ESCAPE_RESET "\x1b[0m"
@@ -145,6 +147,8 @@ pg_logging_init(const char *argv0)
145147
sgr_note = strdup(value);
146148
if (strcmp(name, "locus") == 0)
147149
sgr_locus = strdup(value);
150+
if (strcmp(name, "info_command") == 0)
151+
sgr_info_command = strdup(value);
148152
}
149153
}
150154

@@ -157,6 +161,7 @@ pg_logging_init(const char *argv0)
157161
sgr_warning = SGR_WARNING_DEFAULT;
158162
sgr_note = SGR_NOTE_DEFAULT;
159163
sgr_locus = SGR_LOCUS_DEFAULT;
164+
sgr_info_command = SGR_INFO_COMMAND_DEFAULT;
160165
}
161166
}
162167
}
@@ -353,7 +358,17 @@ pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
353358
if (required_len >= 2 && buf[required_len - 2] == '\n')
354359
buf[required_len - 2] = '\0';
355360

356-
fprintf(stderr, "%s\n", buf);
361+
if (level == PG_LOG_INFO && sgr_info_command &&
362+
(strncmp(buf, "INFO: vacuuming", strlen("INFO: vacuuming")) == 0 ||
363+
strncmp(buf, "INFO: repacking", strlen("INFO: repacking")) == 0 ||
364+
strncmp(buf, "INFO: analyzing", strlen("INFO: analyzing")) == 0))
365+
{
366+
fprintf(stderr, ANSI_ESCAPE_FMT, sgr_info_command);
367+
fprintf(stderr, "%s\n", buf);
368+
fprintf(stderr, ANSI_ESCAPE_RESET);
369+
}
370+
else
371+
fprintf(stderr, "%s\n", buf);
357372
if (log_logfile)
358373
{
359374
fprintf(log_logfile, "%s\n", buf);

0 commit comments

Comments
 (0)