From 06bfeb482d5652e55bdd9d93a9909f26d6c3999a Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 19 Dec 2016 16:41:47 +0100 Subject: [PATCH] Only show Redis logo if logging to stdout / TTY. You can still force the logo in the normal logs. For motivations, check issue #3112. For me the reason is that actually the logo is nice to have in interactive sessions, but inside the logs kinda loses its usefulness, but for the ability of users to recognize restarts easily: for this reason the new startup sequence shows a one liner ASCII "wave" so that there is still a bit of visual clue. Startup logging was modified in order to log events in more obvious ways, and to log more events. Also certain important informations are now more easy to parse/grep since they are printed in field=value style. The option --always-show-logo in redis.conf was added, defaulting to no. --- redis.conf | 8 ++++++++ src/config.c | 4 ++++ src/server.c | 41 ++++++++++++++++++++++++++++++----------- src/server.h | 2 ++ 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/redis.conf b/redis.conf index adc09020..648483c1 100644 --- a/redis.conf +++ b/redis.conf @@ -185,6 +185,14 @@ logfile "" # dbid is a number between 0 and 'databases'-1 databases 16 +# By default Redis shows an ASCII art logo only when started to log to the +# standard output and if the standard output is a TTY. Basically this means +# that normally a logo is displayed only in interactive sessions. +# +# However it is possible to force the pre-4.0 behavior and always show a +# ASCII art logo in startup logs by setting the following option to yes. +always-show-logo yes + ################################ SNAPSHOTTING ################################ # # Save the DB on disk: diff --git a/src/config.c b/src/config.c index 8f3b81a1..54af5bfe 100644 --- a/src/config.c +++ b/src/config.c @@ -283,6 +283,10 @@ void loadServerConfigFromString(char *config) { } fclose(logfp); } + } else if (!strcasecmp(argv[0],"always-show-logo") && argc == 2) { + if ((server.always_show_logo = yesnotoi(argv[1])) == -1) { + err = "argument must be 'yes' or 'no'"; goto loaderr; + } } else if (!strcasecmp(argv[0],"syslog-enabled") && argc == 2) { if ((server.syslog_enabled = yesnotoi(argv[1])) == -1) { err = "argument must be 'yes' or 'no'"; goto loaderr; diff --git a/src/server.c b/src/server.c index aa5b6586..4390360c 100644 --- a/src/server.c +++ b/src/server.c @@ -1400,6 +1400,7 @@ void initServerConfig(void) { server.lazyfree_lazy_eviction = CONFIG_DEFAULT_LAZYFREE_LAZY_EVICTION; server.lazyfree_lazy_expire = CONFIG_DEFAULT_LAZYFREE_LAZY_EXPIRE; server.lazyfree_lazy_server_del = CONFIG_DEFAULT_LAZYFREE_LAZY_SERVER_DEL; + server.always_show_logo = CONFIG_DEFAULT_ALWAYS_SHOW_LOGO; server.lruclock = getLRUClock(); resetServerSaveParams(); @@ -3335,15 +3336,18 @@ void redisAsciiArt(void) { else if (server.sentinel_mode) mode = "sentinel"; else mode = "standalone"; - if (server.syslog_enabled) { + /* Show the ASCII logo if: log file is stdout AND stdout is a + * tty AND syslog logging is disabled. Also show logo if the user + * forced us to do so via redis.conf. */ + int show_logo = ((!server.syslog_enabled && + server.logfile[0] == '\0' && + isatty(fileno(stdout))) || + server.always_show_logo); + + if (!show_logo) { serverLog(LL_NOTICE, - "Redis %s (%s/%d) %s bit, %s mode, port %d, pid %ld ready to start.", - REDIS_VERSION, - redisGitSHA1(), - strtol(redisGitDirty(),NULL,10) > 0, - (sizeof(long) == 8) ? "64" : "32", - mode, server.port, - (long) getpid() + "Running mode=%s, port=%d.", + mode, server.port ); } else { snprintf(buf,1024*16,ascii_logo, @@ -3700,8 +3704,23 @@ int main(int argc, char **argv) { resetServerSaveParams(); loadServerConfig(configfile,options); sdsfree(options); - } else { + } + +// serverLog(LL_WARNING, "_.~\"(_.~\"(_.~\"(_.~\"(_.~\"( Redis is starting..."); + serverLog(LL_WARNING, "oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo"); + + serverLog(LL_WARNING, + "Redis version=%s, bits=%d, commit=%s, modified=%d, pid=%d, just started", + REDIS_VERSION, + (sizeof(long) == 8) ? 64 : 32, + redisGitSHA1(), + strtol(redisGitDirty(),NULL,10) > 0, + (int)getpid()); + + if (argc == 1) { serverLog(LL_WARNING, "Warning: no config file specified, using the default config. In order to specify a config file use %s /path/to/%s.conf", argv[0], server.sentinel_mode ? "sentinel" : "redis"); + } else { + serverLog(LL_WARNING, "Configuration loaded"); } server.supervised = redisIsSupervised(server.supervised_mode); @@ -3716,7 +3735,7 @@ int main(int argc, char **argv) { if (!server.sentinel_mode) { /* Things not needed when running in Sentinel mode. */ - serverLog(LL_WARNING,"Server started, Redis version " REDIS_VERSION); + serverLog(LL_WARNING,"Server initialized"); #ifdef __linux__ linuxMemoryWarnings(); #endif @@ -3731,7 +3750,7 @@ int main(int argc, char **argv) { } } if (server.ipfd_count > 0) - serverLog(LL_NOTICE,"The server is now ready to accept connections on port %d", server.port); + serverLog(LL_NOTICE,"Ready to accept connections"); if (server.sofd > 0) serverLog(LL_NOTICE,"The server is now ready to accept connections at %s", server.unixsocket); } else { diff --git a/src/server.h b/src/server.h index 7ff151de..140897c1 100644 --- a/src/server.h +++ b/src/server.h @@ -151,6 +151,7 @@ typedef long long mstime_t; /* millisecond time type. */ #define CONFIG_DEFAULT_LAZYFREE_LAZY_EVICTION 0 #define CONFIG_DEFAULT_LAZYFREE_LAZY_EXPIRE 0 #define CONFIG_DEFAULT_LAZYFREE_LAZY_SERVER_DEL 0 +#define CONFIG_DEFAULT_ALWAYS_SHOW_LOGO 0 #define ACTIVE_EXPIRE_CYCLE_LOOKUPS_PER_LOOP 20 /* Loopkups per loop. */ #define ACTIVE_EXPIRE_CYCLE_FAST_DURATION 1000 /* Microseconds */ @@ -863,6 +864,7 @@ struct redisServer { char runid[CONFIG_RUN_ID_SIZE+1]; /* ID always different at every exec. */ int sentinel_mode; /* True if this instance is a Sentinel. */ size_t initial_memory_usage; /* Bytes used after initialization. */ + int always_show_logo; /* Show logo even for non-stdout logging. */ /* Modules */ dict *moduleapi; /* Exported APIs dictionary for modules. */ list *loadmodule_queue; /* List of modules to load at startup. */