diff options
| author | N Balachandran <nbalacha@redhat.com> | 2017-07-24 17:48:47 +0530 | 
|---|---|---|
| committer | Shyamsundar Ranganathan <srangana@redhat.com> | 2017-08-03 12:04:50 +0000 | 
| commit | 498164fa45309bd314ff2fcc282b140edf72bc22 (patch) | |
| tree | 352f8e6c7dc924627010e555c63941143ff84e1f /libglusterfs/src | |
| parent | 10da7c37b30f7995bf65dbb4babbbb5216bcc925 (diff) | |
logging: localtime logging, cmdline, volume set option
Despite the fact that appliances generally use UTC, some
users really want log entries in localtime.
fixes gluster/glusterfs#272
feature page: https://review.gluster.org/17807
Backport from master https://review.gluster.org/#/c/16911/
Change-Id: I5fbf2c3eedd9eb128fb3f851dd67b2f4081c8bba
Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Reviewed-on: https://review.gluster.org/17928
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Smoke: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com>
Diffstat (limited to 'libglusterfs/src')
| -rw-r--r-- | libglusterfs/src/common-utils.h | 7 | ||||
| -rw-r--r-- | libglusterfs/src/glusterfs.h | 2 | ||||
| -rw-r--r-- | libglusterfs/src/logging.c | 26 | ||||
| -rw-r--r-- | libglusterfs/src/logging.h | 3 | 
4 files changed, 36 insertions, 2 deletions
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 1d7f09dbc82..022a2a70ff0 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -687,12 +687,15 @@ gf_time_fmt (char *dst, size_t sz_dst, time_t utime, unsigned int fmt)          static gf_timefmts timefmt_last = (gf_timefmts) - 1;          static const char **fmts;          static const char **zeros; -        struct tm tm; +        struct tm tm, *res; +        int localtime = 0;          if (timefmt_last == (gf_timefmts) - 1)                  _gf_timestuff (&timefmt_last, &fmts, &zeros);          if (timefmt_last < fmt) fmt = gf_timefmt_default; -        if (utime && gmtime_r (&utime, &tm) != NULL) { +        localtime = gf_log_get_localtime (); +        res = localtime ? localtime_r (&utime, &tm) : gmtime_r (&utime, &tm); +        if (utime && res != NULL) {                  strftime (dst, sz_dst, fmts[fmt], &tm);          } else {                  strncpy (dst, "N/A", sz_dst); diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index bb925c3d78d..b009b94493d 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -292,6 +292,7 @@  #define GF_LOG_FLUSH_TIMEOUT_MAX 300  #define GF_LOG_FLUSH_TIMEOUT_MIN_STR "30"  #define GF_LOG_FLUSH_TIMEOUT_MAX_STR "300" +#define GF_LOG_LOCALTIME_DEFAULT 0  #define GF_BACKTRACE_LEN        4096  #define GF_BACKTRACE_FRAME_COUNT 7 @@ -416,6 +417,7 @@ struct _cmd_args {           * functions that prevent valgrind from working correctly, like           * dlclose(). */          int                valgrind; +        int                localtime_logging;  };  typedef struct _cmd_args cmd_args_t; diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index c09adecc4f1..0f238d00738 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -141,6 +141,31 @@ gf_log_set_loglevel (gf_loglevel_t level)                  ctx->log.loglevel = level;  } +int +gf_log_get_localtime (void) +{ +        glusterfs_ctx_t *ctx = NULL; + +        ctx = THIS->ctx; + +        if (ctx) +                return ctx->log.localtime; +        else +                /* return global defaults (see gf_log_globals_init) */ +                return 0; +} + +void +gf_log_set_localtime (int on_off) +{ +        glusterfs_ctx_t *ctx = NULL; + +        ctx = THIS->ctx; + +        if (ctx) +                ctx->log.localtime = on_off; +} +  void  gf_log_flush (void)  { @@ -655,6 +680,7 @@ gf_log_globals_init (void *data, gf_loglevel_t level)          ctx->log.logformat        = gf_logformat_withmsgid;          ctx->log.lru_size         = GF_LOG_LRU_BUFSIZE_DEFAULT;          ctx->log.timeout          = GF_LOG_FLUSH_TIMEOUT_DEFAULT; +        ctx->log.localtime        = GF_LOG_LOCALTIME_DEFAULT;          pthread_mutex_init (&ctx->log.log_buf_lock, NULL); diff --git a/libglusterfs/src/logging.h b/libglusterfs/src/logging.h index a7f252acf67..fd9a36d15c2 100644 --- a/libglusterfs/src/logging.h +++ b/libglusterfs/src/logging.h @@ -116,6 +116,7 @@ typedef struct gf_log_handle_ {          uint32_t          timeout;          pthread_mutex_t   log_buf_lock;          struct _gf_timer *log_flush_timer; +        int               localtime;  } gf_log_handle_t; @@ -280,6 +281,8 @@ void gf_log_disable_syslog (void);  void gf_log_enable_syslog (void);  gf_loglevel_t gf_log_get_loglevel (void);  void gf_log_set_loglevel (gf_loglevel_t level); +int gf_log_get_localtime (void); +void gf_log_set_localtime (int);  void gf_log_flush (void);  gf_loglevel_t gf_log_get_xl_loglevel (void *xl);  void gf_log_set_xl_loglevel (void *xl, gf_loglevel_t level);  | 
