summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
authorshishir gowda <shishirng@gluster.com>2010-08-31 04:10:17 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-08-31 07:43:57 -0700
commit4ae3853d857e584189289b33f8ba929fbd9cc7e1 (patch)
tree4527a1a6ea019bc6a5198da01723c6f7c660203a /libglusterfs/src
parentcd5d2fc036003eb0c1a7f91755d3f5aa327067b4 (diff)
Add command logging facility for glusterd
Added new command logging facility to gf_cmd_log() which can be used to log all commands to a .cmd_log_history file situated in the glusterd working directory. Accepts 1 st argument a domain string (e.g: volume, peer..) followed by msg string (similar to gf_log) Signed-off-by: shishir gowda <shishirng@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1404 (need a dump of all the op/mgmt commands) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1404
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/logging.c99
-rw-r--r--libglusterfs/src/logging.h5
2 files changed, 104 insertions, 0 deletions
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c
index 1998fdc3e..c152e4a28 100644
--- a/libglusterfs/src/logging.c
+++ b/libglusterfs/src/logging.c
@@ -51,6 +51,8 @@ static int gf_log_syslog = 0;
gf_loglevel_t gf_log_loglevel; /* extern'd */
FILE *gf_log_logfile;
+static char *cmd_log_filename = NULL;
+static FILE *cmdlogfile = NULL;
void
gf_log_logrotate (int signum)
@@ -412,3 +414,100 @@ gf_log_from_client (const char *msg, char *identifier)
return 0;
}
+
+int
+gf_cmd_log_init (const char *filename)
+{
+ if (!filename){
+ gf_log ("glusterd",GF_LOG_CRITICAL, "gf_cmd_log_init: no "
+ "filename specified\n");
+ return -1;
+ }
+
+ cmd_log_filename = gf_strdup (filename);
+ if (!filename) {
+ gf_log ("glusterd",GF_LOG_CRITICAL, "gf_cmd_log_init: strdup"
+ " error\n");
+ return -1;
+ }
+
+ cmdlogfile = fopen (cmd_log_filename, "a");
+ if (!cmdlogfile){
+ gf_log ("glusterd", GF_LOG_CRITICAL,
+ "gf_cmd_log_init: failed to open logfile \"%s\" "
+ "(%s)\n", cmd_log_filename, strerror (errno));
+ return -1;
+ }
+ return 0;
+}
+
+int
+gf_cmd_log (const char *domain, const char *fmt, ...)
+{
+ va_list ap;
+ struct tm *tm = NULL;
+ char timestr[256];
+ struct timeval tv = {0,};
+ char *str1 = NULL;
+ char *str2 = NULL;
+ char *msg = NULL;
+ size_t len = 0;
+ int ret = 0;
+
+ if (!cmdlogfile)
+ return -1;
+
+
+ if (!domain || !fmt) {
+ gf_log ("glusterd", GF_LOG_TRACE,
+ "logging: invalid argument\n");
+ return -1;
+ }
+
+ ret = gettimeofday (&tv, NULL);
+ if (ret == -1)
+ goto out;
+
+ tm = localtime (&tv.tv_sec);
+
+ va_start (ap, fmt);
+ strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm);
+ snprintf (timestr + strlen (timestr), 256 - strlen (timestr),
+ ".%"GF_PRI_SUSECONDS, tv.tv_usec);
+
+ ret = gf_asprintf (&str1, "[%s] %s : ",
+ timestr, domain);
+ if (ret == -1) {
+ goto out;
+ }
+
+ ret = vasprintf (&str2, fmt, ap);
+ if (ret == -1) {
+ goto out;
+ }
+
+ va_end (ap);
+
+ len = strlen (str1);
+ msg = GF_MALLOC (len + strlen (str2) + 1, gf_common_mt_char);
+
+ strcpy (msg, str1);
+ strcpy (msg + len, str2);
+
+ fprintf (cmdlogfile, "%s\n", msg);
+ fflush (cmdlogfile);
+
+out:
+ if (msg) {
+ GF_FREE (msg);
+ }
+
+ if (str1)
+ GF_FREE (str1);
+
+ if (str2)
+ FREE (str2);
+
+ return (0);
+
+}
diff --git a/libglusterfs/src/logging.h b/libglusterfs/src/logging.h
index f727bfe42..39b593850 100644
--- a/libglusterfs/src/logging.h
+++ b/libglusterfs/src/logging.h
@@ -120,4 +120,9 @@ void gf_log_set_xl_loglevel (void *xl, gf_loglevel_t level);
#define GF_ERROR(xl, format, args...) \
gf_log ((xl)->name, GF_LOG_ERROR, format, ##args)
+int
+gf_cmd_log (const char *domain, const char *fmt, ...);
+
+int
+gf_cmd_log_init (const char *filename);
#endif /* __LOGGING_H__ */