diff options
author | Amar Tumballi <amar@gluster.com> | 2010-08-12 01:54:38 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-08-12 00:45:48 -0700 |
commit | 78615ceea81479b38af43697766bcc04421a256d (patch) | |
tree | f5c95b96121abcd4fa0a8f6ce2f6c5e9d2df8366 /libglusterfs/src/logging.c | |
parent | 553aa029de1817ae182cc86c1d00f8eb8ff52b50 (diff) |
logging enhancements
* per translator loglevel introduced, if set, it will override process
wide log level.
* with extended attribute 'trusted.glusterfs.<xlator-name>.set-log-level'
with the value being '<LOGLEVEL>', one can change log level of particular
translator.
* with extended attribute 'trusted.glusterfs.syslog' with the value
'<BOOLEAN>', one can enable disable syslog for gluster
Signed-off-by: Amar Tumballi <amar@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 601 (Enable changing 'log-level' of GlusterFS process at runtime)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=601
Diffstat (limited to 'libglusterfs/src/logging.c')
-rw-r--r-- | libglusterfs/src/logging.c | 86 |
1 files changed, 74 insertions, 12 deletions
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index 000c2ccd34f..2d3bb4c8f25 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -35,39 +35,73 @@ #include "logging.h" #include "defaults.h" +#ifdef GF_LINUX_HOST_OS +#include <syslog.h> +#endif + + static pthread_mutex_t logfile_mutex; static char *filename = NULL; static uint8_t logrotate = 0; static FILE *logfile = NULL; static gf_loglevel_t loglevel = GF_LOG_MAX; +static int gf_log_syslog = 0; gf_loglevel_t gf_log_loglevel; /* extern'd */ FILE *gf_log_logfile; -void +void gf_log_logrotate (int signum) { logrotate = 1; } +void +gf_log_enable_syslog (void) +{ + gf_log_syslog = 1; +} + +void +gf_log_disable_syslog (void) +{ + gf_log_syslog = 0; +} -gf_loglevel_t +gf_loglevel_t gf_log_get_loglevel (void) { return loglevel; } - void gf_log_set_loglevel (gf_loglevel_t level) { - gf_log_loglevel = loglevel = level; + gf_log_loglevel = loglevel = level; } -void +gf_loglevel_t +gf_log_get_xl_loglevel (void *this) +{ + xlator_t *xl = this; + if (!xl) + return 0; + return xl->loglevel; +} + +void +gf_log_set_xl_loglevel (void *this, gf_loglevel_t level) +{ + xlator_t *xl = this; + if (!xl) + return; + xl->loglevel = level; +} + +void gf_log_fini (void) { pthread_mutex_destroy (&logfile_mutex); @@ -99,6 +133,12 @@ gf_log_init (const char *file) return -1; } +#ifdef GF_LINUX_HOST_OS + /* For the 'syslog' output. one can grep 'GlusterFS' in syslog + for serious logs */ + openlog ("GlusterFS", LOG_PID, LOG_DAEMON); +#endif + gf_log_logfile = logfile; return 0; @@ -162,23 +202,37 @@ _gf_log (const char *domain, const char *file, const char *function, int line, char *msg = NULL; size_t len = 0; int ret = 0; + xlator_t *this = NULL; + gf_loglevel_t xlator_loglevel = 0; + + this = THIS; + + xlator_loglevel = this->loglevel; + if (xlator_loglevel == 0) + xlator_loglevel = loglevel; + + if (level > xlator_loglevel) + goto out; static char *level_strings[] = {"", /* NONE */ + "M", /* EMERGENCY */ + "A", /* ALERT */ "C", /* CRITICAL */ "E", /* ERROR */ "W", /* WARNING */ - "N", /* NORMAL */ + "N", /* NOTICE */ + "I", /* INFO/NORMAL */ "D", /* DEBUG */ "T", /* TRACE */ ""}; - + if (!domain || !file || !function || !fmt) { - fprintf (stderr, - "logging: %s:%s():%d: invalid argument\n", + fprintf (stderr, + "logging: %s:%s():%d: invalid argument\n", __FILE__, __PRETTY_FUNCTION__, __LINE__); return -1; } - + if (!logfile) { fprintf (stderr, "no logfile set\n"); return (-1); @@ -206,7 +260,7 @@ log: tm = localtime (&tv.tv_sec); - if (level > loglevel) { + if (level > xlator_loglevel) { goto out; } @@ -241,13 +295,21 @@ log: len = strlen (str1); msg = GF_MALLOC (len + strlen (str2) + 1, gf_common_mt_char); - + strcpy (msg, str1); strcpy (msg + len, str2); fprintf (logfile, "%s\n", msg); fflush (logfile); + +#ifdef GF_LINUX_HOST_OS + /* We want only serious log in 'syslog', not our debug + and trace logs */ + if (gf_log_syslog && level && (level <= GF_LOG_ERROR)) + syslog ((level-1), "%s\n", msg); +#endif } + unlock: pthread_mutex_unlock (&logfile_mutex); |