mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 00:46:29 +00:00
repmgr: don't display timestamp in log output
Differentiate between repmgr and repmgrd output
This commit is contained in:
2
config.c
2
config.c
@@ -752,7 +752,7 @@ reload_config(t_configuration_options *orig_options)
|
|||||||
{
|
{
|
||||||
log_notice(_("restarting logging with changed parameters\n"));
|
log_notice(_("restarting logging with changed parameters\n"));
|
||||||
logger_shutdown();
|
logger_shutdown();
|
||||||
logger_init(orig_options, progname(), false);
|
logger_init(orig_options, progname());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_changed == true)
|
if (config_changed == true)
|
||||||
|
|||||||
32
log.c
32
log.c
@@ -48,6 +48,11 @@ int log_level = LOG_NOTICE;
|
|||||||
int last_log_level = LOG_NOTICE;
|
int last_log_level = LOG_NOTICE;
|
||||||
int verbose_logging = false;
|
int verbose_logging = false;
|
||||||
int terse_logging = false;
|
int terse_logging = false;
|
||||||
|
/*
|
||||||
|
* Global variable to be set by the main application to ensure any log output
|
||||||
|
* emitted before logger_init is called, is output in the correct format
|
||||||
|
*/
|
||||||
|
int logger_output_mode = OM_DAEMON;
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
stderr_log_with_level(const char *level_name, int level, const char *fmt, ...)
|
stderr_log_with_level(const char *level_name, int level, const char *fmt, ...)
|
||||||
@@ -62,9 +67,7 @@ stderr_log_with_level(const char *level_name, int level, const char *fmt, ...)
|
|||||||
static void
|
static void
|
||||||
_stderr_log_with_level(const char *level_name, int level, const char *fmt, va_list ap)
|
_stderr_log_with_level(const char *level_name, int level, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
time_t t;
|
char buf[100];
|
||||||
struct tm *tm;
|
|
||||||
char buff[100];
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Store the requested level so that if there's a subsequent
|
* Store the requested level so that if there's a subsequent
|
||||||
@@ -74,10 +77,21 @@ _stderr_log_with_level(const char *level_name, int level, const char *fmt, va_li
|
|||||||
|
|
||||||
if (log_level >= level)
|
if (log_level >= level)
|
||||||
{
|
{
|
||||||
time(&t);
|
|
||||||
tm = localtime(&t);
|
/* Format log line prefix with timestamp if in daemon mode */
|
||||||
strftime(buff, 100, "[%Y-%m-%d %H:%M:%S]", tm);
|
if (logger_output_mode == OM_DAEMON)
|
||||||
fprintf(stderr, "%s [%s] ", buff, level_name);
|
{
|
||||||
|
time_t t;
|
||||||
|
struct tm *tm;
|
||||||
|
time(&t);
|
||||||
|
tm = localtime(&t);
|
||||||
|
strftime(buf, 100, "[%Y-%m-%d %H:%M:%S]", tm);
|
||||||
|
fprintf(stderr, "%s [%s] ", buf, level_name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: ", level_name);
|
||||||
|
}
|
||||||
|
|
||||||
vfprintf(stderr, fmt, ap);
|
vfprintf(stderr, fmt, ap);
|
||||||
|
|
||||||
@@ -142,7 +156,7 @@ log_verbose(int level, const char *fmt, ...)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
logger_init(t_configuration_options *opts, const char *ident, bool stderr_only)
|
logger_init(t_configuration_options *opts, const char *ident)
|
||||||
{
|
{
|
||||||
char *level = opts->loglevel;
|
char *level = opts->loglevel;
|
||||||
char *facility = opts->logfacility;
|
char *facility = opts->logfacility;
|
||||||
@@ -180,7 +194,7 @@ logger_init(t_configuration_options *opts, const char *ident, bool stderr_only)
|
|||||||
* STDERR only logging requested - finish here without setting up any further
|
* STDERR only logging requested - finish here without setting up any further
|
||||||
* logging facility.
|
* logging facility.
|
||||||
*/
|
*/
|
||||||
if (stderr_only == true)
|
if (logger_output_mode == OM_COMMAND_LINE)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (facility && *facility)
|
if (facility && *facility)
|
||||||
|
|||||||
6
log.h
6
log.h
@@ -25,6 +25,9 @@
|
|||||||
#define REPMGR_SYSLOG 1
|
#define REPMGR_SYSLOG 1
|
||||||
#define REPMGR_STDERR 2
|
#define REPMGR_STDERR 2
|
||||||
|
|
||||||
|
#define OM_COMMAND_LINE 1
|
||||||
|
#define OM_DAEMON 2
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
stderr_log_with_level(const char *level_name, int level, const char *fmt,...)
|
stderr_log_with_level(const char *level_name, int level, const char *fmt,...)
|
||||||
__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
|
__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
|
||||||
@@ -116,7 +119,7 @@ int detect_log_level(const char *level);
|
|||||||
|
|
||||||
/* Logger initialisation and shutdown */
|
/* Logger initialisation and shutdown */
|
||||||
|
|
||||||
bool logger_init(t_configuration_options * opts, const char *ident, bool stderr_only);
|
bool logger_init(t_configuration_options * opts, const char *ident);
|
||||||
|
|
||||||
bool logger_shutdown(void);
|
bool logger_shutdown(void);
|
||||||
|
|
||||||
@@ -132,5 +135,6 @@ extern int log_type;
|
|||||||
extern int log_level;
|
extern int log_level;
|
||||||
extern int verbose_logging;
|
extern int verbose_logging;
|
||||||
extern int terse_logging;
|
extern int terse_logging;
|
||||||
|
extern int logger_output_mode;
|
||||||
|
|
||||||
#endif /* _REPMGR_LOG_H_ */
|
#endif /* _REPMGR_LOG_H_ */
|
||||||
|
|||||||
9
repmgr.c
9
repmgr.c
@@ -265,6 +265,13 @@ main(int argc, char **argv)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tell the logger we're a command-line program - this will
|
||||||
|
* ensure any output logged before the logger is initialized
|
||||||
|
* will be formatted correctly
|
||||||
|
*/
|
||||||
|
logger_output_mode = OM_COMMAND_LINE;
|
||||||
|
|
||||||
initialize_conninfo_params(&source_conninfo, true);
|
initialize_conninfo_params(&source_conninfo, true);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -837,7 +844,7 @@ main(int argc, char **argv)
|
|||||||
* which makes little sense for a command line program.
|
* which makes little sense for a command line program.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
logger_init(&options, progname(), true);
|
logger_init(&options, progname());
|
||||||
|
|
||||||
if (runtime_options.verbose)
|
if (runtime_options.verbose)
|
||||||
logger_set_verbose();
|
logger_set_verbose();
|
||||||
|
|||||||
@@ -207,6 +207,13 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tell the logger we're a daemon - this will ensure any output logged
|
||||||
|
* before the logger is initialized will be formatted correctly
|
||||||
|
*/
|
||||||
|
logger_output_mode = OM_DAEMON;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse the configuration file, if provided. If no configuration file
|
* Parse the configuration file, if provided. If no configuration file
|
||||||
* was provided, or one was but was incomplete, parse_config() will
|
* was provided, or one was but was incomplete, parse_config() will
|
||||||
@@ -246,7 +253,7 @@ main(int argc, char **argv)
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
logger_init(&local_options, progname(), false);
|
logger_init(&local_options, progname());
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
logger_set_verbose();
|
logger_set_verbose();
|
||||||
|
|||||||
Reference in New Issue
Block a user