patch to add syslog support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

as promised here the patch to add syslog support to glusterfs:

done:
- added syslog support
- added cmd line options: --log [file, syslog], --log-syslog-host,
--log-syslog-facility
- removed unused variable gf_log_logfile
- moved some thread-safe stuff out of the mutex section in _gf_log
- updated some files which were directly using gf_log_file to use the
proper gf_log functions
- gf_log_file was renamed and is local to logging.c now to make clear it
should never be used directly
- renamed some function names like gf_log_set_loglevel to
gf_log_set_level to avoid redundancies in names

todo:
- add support for syslog-host option, right now always /dev/log or
127.0.0.1 is used

Please let me know what you think. Unluckily I didn't get any feedback
to my previous patch yet?

Corin

* local directory is at gluster@xxxxxxxxxx/glusterfs--mainline--3.0--patch-842
* comparing to gluster@xxxxxxxxxx/glusterfs--mainline--3.0--patch-842
M  configure.ac
M  glusterfsd/src/glusterfsd.c
M  glusterfsd/src/glusterfsd.h
M  libglusterfs/src/common-utils.c
M  libglusterfs/src/glusterfs.h
M  libglusterfs/src/logging.c
M  libglusterfs/src/logging.h
M  xlators/protocol/client/src/client-protocol.c
M  xlators/protocol/server/src/server-protocol.c
M  libglusterfsclient/src/libglusterfsclient.c
M  transport/socket/src/socket.c

* modified files

--- orig/configure.ac
+++ mod/configure.ac
@@ -14,7 +14,7 @@ dnl
 dnl You should have received a copy of the GNU General Public License
 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-AC_INIT([glusterfs],[1.4.0tla842],[gluster-users@xxxxxxxxxxx])
+AC_INIT([glusterfs],[1.4.0tla843],[gluster-users@xxxxxxxxxxx])
 
 AM_INIT_AUTOMAKE
 
--- orig/glusterfsd/src/glusterfsd.c
+++ mod/glusterfsd/src/glusterfsd.c
@@ -89,12 +89,19 @@ static struct argp_option gf_options[] =
 	{"spec-file", ARGP_VOLUME_FILE_KEY, "VOLFILE", OPTION_HIDDEN, 
 	 "File to use as VOLFILE [default : "DEFAULT_CLIENT_VOLUME_FILE" or "
 	 DEFAULT_SERVER_VOLUME_FILE"]"},
+ 	{"log", ARGP_LOG_KEY, "FACILITY", 0, 
+ 	 "Logging facility to use.  Valid options are FILE, SYSLOG "
+	 "[default: FILE]"},
  	{"log-level", ARGP_LOG_LEVEL_KEY, "LOGLEVEL", 0, 
- 	 "Logging severity.  Valid options are DEBUG, WARNING, ERROR, "
-	 "CRITICAL and NONE [default: WARNING]"},
+ 	 "Logging severity. Valid options are DEBUG, NORMAL, WARNING, ERROR, "
+	 "CRITICAL and NONE [default: NORMAL]"},
  	{"log-file", ARGP_LOG_FILE_KEY, "LOGFILE", 0, 
  	 "File to use for logging [default: " 
 	 DEFAULT_LOG_FILE_DIRECTORY "/" PACKAGE_NAME ".log" "]"},
+ 	{"log-syslog-host", ARGP_LOG_SYSLOG_HOST_KEY, "HOST", 0, 
+ 	 "Host to use for logging [default: " DEFAULT_LOG_SYSLOG_HOST "]"},
+ 	{"log-syslog-facility", ARGP_LOG_SYSLOG_FACILITY_KEY, "FACILITY", 0, 
+ 	 "Syslog facility, Valid options are USER, MAIL, DAEMON, AUTH, AUTHPRIV, SYSLOG, LPR, NEWS, UUCP, CRON, FTP, ALERT, LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7 [default: " DEFAULT_LOG_SYSLOG_FACILITY "]"},
  	
  	{0, 0, 0, 0, "Advanced Options:"},
  	{"volfile-server-port", ARGP_VOLFILE_SERVER_PORT_KEY, "PORT", 0, 
@@ -143,30 +150,20 @@ static struct argp argp = { gf_options, 
 static void 
 _gf_dump_details (int argc, char **argv)
 {
-        extern FILE *gf_log_logfile;
+        char         str[4096];
         int          i = 0;
-        char         timestr[256];
-        time_t       utime = 0;
-        struct tm   *tm = NULL;
-
-	utime = time (NULL);
-	tm    = localtime (&utime);
 
-        /* Which TLA? What time? */
-        strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); 
-        fprintf (gf_log_logfile, "\nVersion      : %s %s built on %s %s\n", 
+        gf_log ("glusterfs", GF_LOG_NORMAL, "Version: %s %s built on %s %s", 
                  PACKAGE_NAME, PACKAGE_VERSION, __DATE__, __TIME__);
-        fprintf (gf_log_logfile, "TLA Revision : %s\n", 
+        gf_log ("glusterfs", GF_LOG_NORMAL, "TLA Revision: %s", 
                  GLUSTERFS_REPOSITORY_REVISION);
-        fprintf (gf_log_logfile, "Starting Time: %s\n", timestr);
-        fprintf (gf_log_logfile, "Command line : ");
 
+        strcpy(str, "Command line: ");
         for (i = 0; i < argc; i++) {
-                fprintf (gf_log_logfile, "%s ", argv[i]);
+                strcat(str, argv[i]);
+                strcat(str, " ");
         }
-
-        fprintf (gf_log_logfile, "\n");
-        fflush (gf_log_logfile);
+        gf_log ("glusterfs", GF_LOG_NORMAL, "%s", str);
 }
 
 
@@ -634,6 +631,19 @@ parse_opts (int key, char *arg, struct a
 		cmd_args->volume_file = strdup (arg);
 		break;
 		
+	case ARGP_LOG_KEY:
+		if (strcasecmp (arg, "FILE") == 0) {
+			cmd_args->log = "FILE";
+			break;
+		}
+		else if (strcasecmp (arg, "SYSLOG") == 0) {
+			cmd_args->log = "SYSLOG";
+			break;
+		}
+
+		argp_failure (state, -1, 0, "unknown log facility %s", arg);
+		break;
+		
 	case ARGP_LOG_LEVEL_KEY:
 		if (strcasecmp (arg, ARGP_LOG_LEVEL_NONE_OPTION) == 0) {
 			cmd_args->log_level = GF_LOG_NONE;
@@ -671,6 +681,96 @@ parse_opts (int key, char *arg, struct a
 		cmd_args->log_file = strdup (arg);
 		break;
 		
+	case ARGP_LOG_SYSLOG_HOST_KEY:
+		argp_failure (state, -1, 0, "setting syslog-host is not yet supported, we'll always use /dev/log");
+		//cmd_args->log_syslog_host = strdup (arg);
+		break;
+		
+	case ARGP_LOG_SYSLOG_FACILITY_KEY:
+		if (strcasecmp (arg, "USER") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "MAIL") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "DAEMON") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "AUTH") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "AUTHPRIV") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "SYSLOG") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "LPR") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "NEWS") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "UUCP") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "CRON") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "FTP") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "ALERT") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "LOCAL0") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "LOCAL1") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "LOCAL2") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "LOCAL3") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "LOCAL4") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "LOCAL5") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "LOCAL6") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		else if (strcasecmp (arg, "LOCAL7") == 0) {
+			cmd_args->log_syslog_facility = strdup(arg);
+			break;
+		}
+		
+		argp_failure (state, -1, 0, "unknown syslog facility %s", arg);
+		break;
+		
 	case ARGP_VOLFILE_SERVER_PORT_KEY:
 		n = 0;
 		
@@ -887,6 +987,7 @@ main (int argc, char *argv[])
 	cmd_args = &ctx->cmd_args;
 
 	/* parsing command line arguments */
+	cmd_args->log = DEFAULT_LOG;
 	cmd_args->log_level = DEFAULT_LOG_LEVEL;
 	cmd_args->fuse_direct_io_mode_flag = _gf_true;
 	
@@ -913,6 +1014,12 @@ main (int argc, char *argv[])
 			  DEFAULT_LOG_FILE_DIRECTORY "/%s.log", 
 			  basename (base_exec_name));
 	
+	if (cmd_args->log_syslog_host == NULL)
+		cmd_args->log_syslog_host = strdup(DEFAULT_LOG_SYSLOG_HOST);
+		
+	if (cmd_args->log_syslog_facility == NULL)
+		cmd_args->log_syslog_facility = strdup(DEFAULT_LOG_SYSLOG_FACILITY);
+	
 	free (base_exec_name);
 
 	ctx->event_pool = event_pool_new (DEFAULT_EVENT_POOL_SIZE);
@@ -951,8 +1058,19 @@ main (int argc, char *argv[])
  		}
  	}
 	
+	if (strcasecmp (cmd_args->log, "FILE") == 0) {
+		FREE(cmd_args->log_syslog_host);
+		cmd_args->log_syslog_host = NULL;
+		FREE(cmd_args->log_syslog_facility);
+		cmd_args->log_syslog_facility = NULL;
+	}
+	else if (strcasecmp (cmd_args->log, "SYSLOG") == 0) {
+		FREE(cmd_args->log_file);
+		cmd_args->log_file = NULL;
+	}
+	
 	/* initializing logs */
-	if (cmd_args->run_id) {
+	if (cmd_args->run_id && cmd_args->log_file) {
 		ret = stat (cmd_args->log_file, &stbuf);
 		/* If its /dev/null, or /dev/stdout, /dev/stderr, 
 		 * let it use the same, no need to alter 
@@ -977,13 +1095,12 @@ main (int argc, char *argv[])
 	
 	gf_global_variable_init ();
 
-	if (gf_log_init (cmd_args->log_file) == -1) {
+	if (gf_log_init (cmd_args->log_file, cmd_args->log_syslog_host, cmd_args->log_syslog_facility) == -1) {
 		fprintf (stderr, 
-			 "failed to open logfile %s.  exiting\n", 
-			 cmd_args->log_file);
+			 "failed to start logging. exiting\n");
 		return -1;
 	}
-	gf_log_set_loglevel (cmd_args->log_level);
+	gf_log_set_level (cmd_args->log_level);
 	
 	/* setting up environment  */
 	lim.rlim_cur = RLIM_INFINITY;
@@ -1001,7 +1118,7 @@ main (int argc, char *argv[])
 	signal (SIGSEGV, gf_print_trace);
 	signal (SIGABRT, gf_print_trace);
 	signal (SIGPIPE, SIG_IGN);
-	signal (SIGHUP, gf_log_logrotate);
+	signal (SIGHUP, gf_log_rotate);
 	signal (SIGTERM, cleanup_and_exit);
 	/* This is used to dump details */
 	/* signal (SIGUSR2, (sighandler_t) glusterfs_stats); */
--- orig/glusterfsd/src/glusterfsd.h
+++ mod/glusterfsd/src/glusterfsd.h
@@ -28,7 +28,10 @@
 #define DEFAULT_CLIENT_VOLUME_FILE            CONFDIR "/glusterfs.vol"
 #define DEFAULT_SERVER_VOLUME_FILE            CONFDIR "/glusterfsd.vol"
 #define DEFAULT_LOG_FILE_DIRECTORY            DATADIR "/log/glusterfs"
-#define DEFAULT_LOG_LEVEL                     GF_LOG_WARNING
+#define DEFAULT_LOG_LEVEL                     GF_LOG_NORMAL
+#define DEFAULT_LOG                           "FILE"
+#define DEFAULT_LOG_SYSLOG_HOST               "127.0.0.1"
+#define DEFAULT_LOG_SYSLOG_FACILITY           "DAEMON"
 
 #define DEFAULT_EVENT_POOL_SIZE            16384
 
@@ -54,6 +57,9 @@ enum argp_option_keys {
 	ARGP_VOLUME_FILE_KEY = 'f', 
 	ARGP_LOG_LEVEL_KEY = 'L', 
 	ARGP_LOG_FILE_KEY = 'l', 
+	ARGP_LOG_KEY = 'a', 
+	ARGP_LOG_SYSLOG_HOST_KEY = 'b', 
+	ARGP_LOG_SYSLOG_FACILITY_KEY = 'c',
 	ARGP_VOLFILE_SERVER_PORT_KEY = 131, 
 	ARGP_VOLFILE_SERVER_TRANSPORT_KEY = 132, 
 	ARGP_PID_FILE_KEY = 'p',
--- orig/libglusterfs/src/common-utils.c
+++ mod/libglusterfs/src/common-utils.c
@@ -238,112 +238,112 @@ get_global_ctx_ptr (void)
 void 
 gf_log_volume_file (FILE *specfp)
 {
-	extern FILE *gf_log_logfile;
 	int          lcount = 0;
 	char         data[GF_UNIT_KB];
 	
 	fseek (specfp, 0L, SEEK_SET);
 	
-	fprintf (gf_log_logfile, "given volfile\n");
-	fprintf (gf_log_logfile, "+-----\n");
+	gf_log ("glusterfs", GF_LOG_NORMAL, "given volfile");
+	gf_log ("glusterfs", GF_LOG_NORMAL, "+-----");
 	while (!feof (specfp)) {
 		if (fgets (data, GF_UNIT_KB, specfp) == NULL)
 			break;
 		lcount++;
-		fprintf (gf_log_logfile, "%3d: %s", lcount, data);
+		if (data[0]) 
+		{
+			data[strlen(data)-1] = 0; // cut off \n
+		}
+		gf_log ("glusterfs", GF_LOG_NORMAL, "%3d: %s", lcount, data);
 	}
-	fprintf (gf_log_logfile, "+-----\n");
-	fflush (gf_log_logfile);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "+-----");
+
 	fseek (specfp, 0L, SEEK_SET);
 }
 
 static void 
-gf_dump_config_flags (int fd)
+gf_dump_config_flags ()
 {
-
-	write (fd, "configuration details:\n", 22);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "configuration details:");
 
 /* have argp */
 #ifdef HAVE_ARGP
-	write (fd, "argp 1\n", 7);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "argp 1");
 #endif
 
 /* ifdef if found backtrace */
 #ifdef HAVE_BACKTRACE 
-	write (fd, "backtrace 1\n", 12);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "backtrace 1");
 #endif
 
 /* Berkeley-DB version has cursor->get() */
 #ifdef HAVE_BDB_CURSOR_GET 
-	write (fd, "bdb->cursor->get 1\n", 19);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "bdb->cursor->get 1");
 #endif
 
 /* Define to 1 if you have the <db.h> header file. */
 #ifdef HAVE_DB_H 
-	write (fd, "db.h 1\n", 7);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "db.h 1");
 #endif
 
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #ifdef HAVE_DLFCN_H 
-	write (fd, "dlfcn 1\n", 8);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "dlfcn 1");
 #endif
 
 /* define if fdatasync exists */
 #ifdef HAVE_FDATASYNC 
-	write (fd, "fdatasync 1\n", 12);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "fdatasync 1");
 #endif
 
 /* Define to 1 if you have the `pthread' library (-lpthread). */
 #ifdef HAVE_LIBPTHREAD 
-	write (fd, "libpthread 1\n", 13);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "libpthread 1");
 #endif
 
 /* define if llistxattr exists */
 #ifdef HAVE_LLISTXATTR 
-	write (fd, "llistxattr 1\n", 13);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "llistxattr 1");
 #endif
 
 /* define if found setfsuid setfsgid */
 #ifdef HAVE_SET_FSID 
-	write (fd, "setfsid 1\n", 10);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "setfsid 1");
 #endif
 
 /* define if found spinlock */
 #ifdef HAVE_SPINLOCK 
-	write (fd, "spinlock 1\n", 11);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "spinlock 1");
 #endif
 
 /* Define to 1 if you have the <sys/epoll.h> header file. */
 #ifdef HAVE_SYS_EPOLL_H 
-	write (fd, "epoll.h 1\n", 10);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "epoll.h 1");
 #endif
 
 /* Define to 1 if you have the <sys/extattr.h> header file. */
 #ifdef HAVE_SYS_EXTATTR_H 
-	write (fd, "extattr.h 1\n", 12);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "extattr.h 1");
 #endif
 
 /* Define to 1 if you have the <sys/xattr.h> header file. */
 #ifdef HAVE_SYS_XATTR_H 
-	write (fd, "xattr.h 1\n", 10);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "xattr.h 1");
 #endif
 
 /* define if found tv_nsec */
 #ifdef HAVE_TV_NSEC 
-	write (fd, "tv_nsec 1\n", 10);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "tv_nsec 1");
 #endif
 
 /* define if found tv_nsec bsd */
 #ifdef HAVE_BSD_NSEC
-	write (fd, "tv_nsec bsd 1\n",14);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "tv_nsec bsd 1");
 #endif
 
 /* Define to the full name and version of this package. */
 #ifdef PACKAGE_STRING 
 	{
-		char msg[128];
-		sprintf (msg, "package-string: %s\n", PACKAGE_STRING); 
-		write (fd, msg, strlen (msg));
+		gf_log ("glusterfs", GF_LOG_NORMAL, "package-string: %s", PACKAGE_STRING); 
 	}
 #endif
 
@@ -356,13 +356,11 @@ gf_dump_config_flags (int fd)
 void
 gf_print_trace (int32_t signum)
 {
-	extern FILE *gf_log_logfile;
-	int fd = fileno (gf_log_logfile);
 	char msg[1024];
 
 
 	/* Pending frames, (if any), list them in order */
-	write (fd, "pending frames:\n", 16);
+	gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "pending frames:");
 	{
 		extern glusterfs_ctx_t *gf_global_ctx;
 		glusterfs_ctx_t *ctx = gf_global_ctx;
@@ -385,19 +383,16 @@ gf_print_trace (int32_t signum)
 					 tmp->root->type, 
 					 gf_cbk_list[tmp->root->op]);
 			
-			write (fd, msg, strlen (msg));
+			gf_log ("glusterfs", GF_LOG_NORMAL, "%s", msg);
 			trav = trav->next;
 		}
-		write (fd, "\n", 1);
 	}
 
-	sprintf (msg, "patchset: %s\n", GLUSTERFS_REPOSITORY_REVISION); 
-	write (fd, msg, strlen (msg));
+	gf_log ("glusterfs", GF_LOG_NORMAL, "patchset: %s", GLUSTERFS_REPOSITORY_REVISION); 
 
-	sprintf (msg, "signal received: %d\n", signum); 
-	write (fd, msg, strlen (msg));
+	gf_log ("glusterfs", GF_LOG_NORMAL, "signal received: %d", signum); 
 
-	gf_dump_config_flags (fd);
+	gf_dump_config_flags ();
 #if HAVE_BACKTRACE
 	/* Print 'backtrace' */
 	{
@@ -405,9 +400,8 @@ gf_print_trace (int32_t signum)
 		size_t size;
     
 		size = backtrace (array, 200);
-		backtrace_symbols_fd (&array[1], size-1, fd);
-		sprintf (msg, "---------\n");
-		write (fd, msg, strlen (msg));
+		backtrace_symbols (&array[1], size-1);
+		gf_log ("glusterfs", GF_LOG_NORMAL, "%s", "---------");
 	}
 #endif /* HAVE_BACKTRACE */
   
--- orig/libglusterfs/src/glusterfs.h
+++ mod/libglusterfs/src/glusterfs.h
@@ -209,8 +209,12 @@ struct _cmd_args {
 	/* basic options */
 	char            *volfile_server;
 	char            *volume_file;
+	char            *log;
 	gf_loglevel_t    log_level;
 	char            *log_file;
+	char            *log_syslog_host;
+	char            *log_syslog_facility;
+
 	/* advanced options */
 	uint32_t         volfile_server_port;
 	char            *volfile_server_transport;
--- orig/libglusterfs/src/logging.c
+++ mod/libglusterfs/src/logging.c
@@ -30,74 +30,155 @@
 #include <locale.h>
 #include <string.h>
 #include <stdlib.h>
+#include <sys/syslog.h>
 #include "logging.h"
 
 
-static pthread_mutex_t  logfile_mutex;
-static char            *filename = NULL;
-static uint8_t          logrotate = 0;
+static pthread_mutex_t  log_file_mutex;
+static FILE            *log_file_fd = NULL;
+static char            *log_file_filename = NULL;
 
-static FILE            *logfile = NULL;
-static gf_loglevel_t    loglevel = GF_LOG_MAX;
+static char            *log_syslog_host = NULL;
+static int              log_syslog_facility = 0;
+
+static uint8_t          log_rotate = 0;
+
+static gf_loglevel_t    log_level = GF_LOG_MAX;
 
 gf_loglevel_t           gf_log_loglevel; /* extern'd */
-FILE                   *gf_log_logfile;
 
 
 void 
-gf_log_logrotate (int signum)
+gf_log_rotate (int signum)
 {
-	logrotate = 1;
+	log_rotate = 1;
 }
 
 
 gf_loglevel_t 
-gf_log_get_loglevel (void)
+gf_log_get_level (void)
 {
-	return loglevel;
+	return log_level;
 }
 
 
 void
-gf_log_set_loglevel (gf_loglevel_t level)
+gf_log_set_level (gf_loglevel_t level)
 {
-	gf_log_loglevel = loglevel = level;
+	gf_log_loglevel = log_level = level;
 }
 
 
 void 
 gf_log_fini (void)
 {
-	pthread_mutex_destroy (&logfile_mutex);
+	pthread_mutex_destroy (&log_file_mutex);
 }
 
 
 int
-gf_log_init (const char *file)
+gf_log_init (const char *file, const char *syslog_host, const char *syslog_facility)
 {
-	if (!file){
-		fprintf (stderr, "gf_log_init: no filename specified\n");
+	if (!file && !syslog_host){
+		fprintf (stderr, "gf_log_init: no log_file_filename nor syslog host specified\n");
 		return -1;
 	}
 
-	pthread_mutex_init (&logfile_mutex, NULL);
+	if (file)
+	{
+		pthread_mutex_init (&log_file_mutex, NULL);
 
-	filename = strdup (file);
-	if (!filename) {
+		log_file_filename = strdup (file);
+		if (!log_file_filename) {
 		fprintf (stderr, "gf_log_init: strdup error\n");
 		return -1;
 	}
 
-	logfile = fopen (file, "a");
-	if (!logfile){
+		log_file_fd = fopen (file, "a");
+		if (!log_file_fd){
 		fprintf (stderr,
 			 "gf_log_init: failed to open logfile \"%s\" (%s)\n",
 			 file,
 			 strerror (errno));
 		return -1;
 	}
+	}
 
-	gf_log_logfile = logfile;
+	if (syslog_host)
+	{
+		log_syslog_host = strdup (syslog_host);
+		if (!log_syslog_host) {
+			fprintf (stderr, "gf_log_init: strdup error\n");
+			return -1;
+		}
+
+		if (strcasecmp (syslog_facility, "USER") == 0) {
+			log_syslog_facility = LOG_USER;
+		}
+		else if (strcasecmp (syslog_facility, "MAIL") == 0) {
+			log_syslog_facility = LOG_MAIL;
+		}
+		else if (strcasecmp (syslog_facility, "DAEMON") == 0) {
+			log_syslog_facility = LOG_DAEMON;
+		}
+		else if (strcasecmp (syslog_facility, "AUTH") == 0) {
+			log_syslog_facility = LOG_AUTH;
+		}
+		else if (strcasecmp (syslog_facility, "AUTHPRIV") == 0) {
+			log_syslog_facility = LOG_AUTHPRIV;
+		}
+		else if (strcasecmp (syslog_facility, "SYSLOG") == 0) {
+			log_syslog_facility = LOG_SYSLOG;
+		}
+		else if (strcasecmp (syslog_facility, "LPR") == 0) {
+			log_syslog_facility = LOG_LPR;
+		}
+		else if (strcasecmp (syslog_facility, "NEWS") == 0) {
+			log_syslog_facility = LOG_NEWS;
+		}
+		else if (strcasecmp (syslog_facility, "UUCP") == 0) {
+			log_syslog_facility = LOG_UUCP;
+		}
+		else if (strcasecmp (syslog_facility, "CRON") == 0) {
+			log_syslog_facility = LOG_CRON;
+		}
+		else if (strcasecmp (syslog_facility, "FTP") == 0) {
+			log_syslog_facility = LOG_FTP;
+		}
+		else if (strcasecmp (syslog_facility, "ALERT") == 0) {
+			log_syslog_facility = LOG_ALERT;
+		}
+		else if (strcasecmp (syslog_facility, "LOCAL0") == 0) {
+			log_syslog_facility = LOG_LOCAL0;
+		}
+		else if (strcasecmp (syslog_facility, "LOCAL1") == 0) {
+			log_syslog_facility = LOG_LOCAL1;
+		}
+		else if (strcasecmp (syslog_facility, "LOCAL2") == 0) {
+			log_syslog_facility = LOG_LOCAL2;
+		}
+		else if (strcasecmp (syslog_facility, "LOCAL3") == 0) {
+			log_syslog_facility = LOG_LOCAL3;
+		}
+		else if (strcasecmp (syslog_facility, "LOCAL4") == 0) {
+			log_syslog_facility = LOG_LOCAL4;
+		}
+		else if (strcasecmp (syslog_facility, "LOCAL5") == 0) {
+			log_syslog_facility = LOG_LOCAL5;
+		}
+		else if (strcasecmp (syslog_facility, "LOCAL6") == 0) {
+			log_syslog_facility = LOG_LOCAL6;
+		}
+		else if (strcasecmp (syslog_facility, "LOCAL7") == 0) {
+			log_syslog_facility = LOG_LOCAL7;
+		}
+		else {
+			fprintf (stderr, "gf_log_init: invalid syslog facility %s\n", syslog_facility);
+			return -1;
+		}
+
+		openlog(NULL, LOG_NDELAY|LOG_CONS|LOG_PID, log_syslog_facility);
+	}
 
 	return 0;
 }
@@ -106,27 +187,47 @@ gf_log_init (const char *file)
 void 
 gf_log_lock (void)
 {
-	pthread_mutex_lock (&logfile_mutex);
+	if (log_file_filename)
+	{
+		pthread_mutex_lock (&log_file_mutex);
+	}
 }
 
 
 void 
 gf_log_unlock (void)
 {
-	pthread_mutex_unlock (&logfile_mutex);
+	if (log_file_filename)
+	{
+		pthread_mutex_unlock (&log_file_mutex);
+	}
 }
 
 
 void
 gf_log_cleanup (void)
 {
-	pthread_mutex_destroy (&logfile_mutex);
+	if (log_file_filename)
+	{
+		if (log_file_fd)
+		{
+			fclose (log_file_fd);
+			log_file_fd = NULL;
+		}
+
+		pthread_mutex_destroy (&log_file_mutex);
+	}
+
+	if (log_syslog_host)
+	{
+		closelog();
+	}
 }
 
 
 int
-_gf_log (const char *domain, const char *file, const char *function, int line,
-	 gf_loglevel_t level, const char *fmt, ...)
+_gf_log (const char *domain, const char *file, const char *function, const int line,
+	 const gf_loglevel_t level, const char *fmt, ...)
 {
 	const char  *basename = NULL;
 	FILE        *new_logfile = NULL;
@@ -150,57 +251,94 @@ _gf_log (const char *domain, const char 
 		return -1;
 	}
   
-	if (!logfile) {
+	if (log_file_filename)
+	{  
+		if (!log_file_fd) {
 		fprintf (stderr, "no logfile set\n");
 		return (-1);
 	}
 
-	if (logrotate) {
-		logrotate = 0;
+		if (log_rotate) {
+			log_rotate = 0;
 
-		new_logfile = fopen (filename, "a");
+			new_logfile = fopen (log_file_filename, "a");
 		if (!new_logfile) {
-			gf_log ("logrotate", GF_LOG_CRITICAL,
+				gf_log ("log_rotate", GF_LOG_CRITICAL,
 				"failed to open logfile %s (%s)",
-				filename, strerror (errno));
+					log_file_filename, strerror (errno));
 			goto log;
 		}
 
-		fclose (logfile);
-		gf_log_logfile = logfile = new_logfile;
+			fclose (log_file_fd);
+			log_file_fd = new_logfile;
+		}
 	}
 
 log:
 	utime = time (NULL);
 	tm    = localtime (&utime);
 
-	if (level > loglevel) {
+	if (level > log_level) {
 		goto out;
 	}
 
-	pthread_mutex_lock (&logfile_mutex);
-	{
-		va_start (ap, fmt);
-
-		strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); 
-
 		basename = strrchr (file, '/');
 		if (basename)
 			basename++;
 		else
 			basename = file;
 
-		fprintf (logfile, "%s %s [%s:%d:%s] %s: ",
+	strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); 
+
+	va_start (ap, fmt);
+
+	if (log_file_filename)
+	{
+		pthread_mutex_lock (&log_file_mutex);
+		{
+			fprintf (log_file_fd, "%s %s [%s:%d:%s] %s: ",
 			 timestr, level_strings[level],
 			 basename, line, function,
 			 domain);
       
-		vfprintf (logfile, fmt, ap);
-		va_end (ap);
-		fprintf (logfile, "\n");
-		fflush (logfile);
+			vfprintf (log_file_fd, fmt, ap);
+			fprintf (log_file_fd, "\n");
+			fflush (log_file_fd);
+		}
+		pthread_mutex_unlock (&log_file_mutex);
 	}
-	pthread_mutex_unlock (&logfile_mutex);
+	
+	if (log_syslog_host)
+	{
+		int syslog_level = LOG_EMERG;
+		
+		switch (level)
+		{
+			case GF_LOG_DEBUG:
+				syslog_level = LOG_DEBUG;
+				break;
+			case GF_LOG_NORMAL:
+				syslog_level = LOG_NOTICE;
+				break;
+			case GF_LOG_WARNING:
+				syslog_level = LOG_WARNING;
+				break;
+			case GF_LOG_ERROR:
+				syslog_level = LOG_ERR;
+				break;
+			case GF_LOG_CRITICAL:
+				syslog_level = LOG_CRIT;
+				break;
+			case GF_LOG_TRACE:
+			case GF_LOG_NONE:
+				fprintf (stderr, "strange loglevel given\n");
+				return (-1);
+		}
+
+		vsyslog(syslog_level, fmt, ap);
+	}
+
+	va_end (ap);
 
 out:
 	return (0);
--- orig/libglusterfs/src/logging.h
+++ mod/libglusterfs/src/logging.h
@@ -100,27 +100,28 @@ extern gf_loglevel_t gf_log_loglevel;
 
 			
 void 
-gf_log_logrotate (int signum);
+gf_log_rotate (int signum);
 
 int32_t 
 _gf_log (const char *domain,
 	 const char *file,
 	 const char *function,
-	 int32_t line,
-	 gf_loglevel_t level,
+	 const int32_t line,
+	 const gf_loglevel_t level,
 	 const char *fmt, ...);
 int32_t 
-gf_log_init (const char *filename);
+gf_log_init (const char *file, const char *syslog_host, const char *syslog_facility);
 
 void gf_log_lock (void);
 void gf_log_unlock (void);
 
 gf_loglevel_t 
-gf_log_get_loglevel (void);
+gf_log_get_level (void);
 void 
-gf_log_set_loglevel (gf_loglevel_t level);
+gf_log_set_level (gf_loglevel_t level);
 
 #define GF_DEBUG(xl, format, args...) gf_log ((xl)->name, GF_LOG_DEBUG, format, ##args)
+#define GF_NORMAL(xl, format, args...) gf_log ((xl)->name, GF_LOG_NORMAL, format, ##args)
 #define GF_WARNING(xl, format, args...) gf_log ((xl)->name, GF_LOG_WARNING, format, ##args)
 #define GF_ERROR(xl, format, args...) gf_log ((xl)->name, GF_LOG_ERROR, format, ##args)
 
--- orig/libglusterfsclient/src/libglusterfsclient.c
+++ mod/libglusterfsclient/src/libglusterfsclient.c
@@ -401,7 +401,7 @@ glusterfs_init (glusterfs_init_ctx_t *in
 
 	if (first_init)
         {
-                ret = gf_log_init (ctx->gf_ctx.cmd_args.log_file);
+                ret = gf_log_init (ctx->gf_ctx.cmd_args.log_file, ctx->gf_ctx.cmd_args.log_syslog_host, ctx->gf_ctx.cmd_args.log_syslog_facility);
                 if (ret == -1) {
 			fprintf (stderr, 
 				 "libglusterfsclient: %s:%s():%d: failed to open logfile \"%s\"\n", 
@@ -414,7 +414,7 @@ glusterfs_init (glusterfs_init_ctx_t *in
                         return NULL;
                 }
 
-                gf_log_set_loglevel (ctx->gf_ctx.cmd_args.log_level);
+                gf_log_set_level (ctx->gf_ctx.cmd_args.log_level);
         }
 
         if (init_ctx->specfp) {
--- orig/transport/socket/src/socket.c
+++ mod/transport/socket/src/socket.c
@@ -729,6 +729,8 @@ socket_connect_finish (transport_t *this
 		goto unlock;
 	      }
 
+	    GF_NORMAL(this->xl, "connection established");
+
 	    priv->connected = 1;
 	    priv->connect_finish_log = 0;
 	    event = GF_EVENT_CHILD_UP;
--- orig/xlators/protocol/client/src/client-protocol.c
+++ mod/xlators/protocol/client/src/client-protocol.c
@@ -5690,7 +5690,7 @@ client_protocol_reconnect (void *trans_p
 		if (cprivate->connected == 0) {
 			tv.tv_sec = 10;
 
-			gf_log (trans->xl->name, GF_LOG_DEBUG, 
+			gf_log (trans->xl->name, GF_LOG_NORMAL, 
 				"attempting reconnect");
 			transport_connect (trans);
 
@@ -6263,6 +6263,8 @@ notify (xlator_t *this,
 		struct timeval tv = {0, 0};
 		xlator_list_t *parent = NULL;
 
+		gf_log (this->name, GF_LOG_NORMAL, "connection lost");
+
 		parent = this->parents;
 		while (parent) {
 			parent->xlator->notify (parent->xlator,
--- orig/xlators/protocol/server/src/server-protocol.c
+++ mod/xlators/protocol/server/src/server-protocol.c
@@ -6852,7 +6852,7 @@ mop_setvolume (call_frame_t *frame,
 	ret = gf_authenticate (params, config_params, 
 			       server_private->auth_modules);
 	if (ret == AUTH_ACCEPT) {
-		gf_log (trans->xl->name, GF_LOG_DEBUG,
+		gf_log (trans->xl->name, GF_LOG_NORMAL,
 			"accepted client from %s",
 			peerinfo->identifier);
 		op_ret = 0;
@@ -7762,6 +7762,11 @@ notify (xlator_t *this,
 		break;
 	case GF_EVENT_POLLERR:
 	{
+		peer_info_t *peerinfo = NULL;
+
+		peerinfo = &(trans->peerinfo);
+		gf_log (trans->xl->name, GF_LOG_NORMAL, "lost client from %s", peerinfo->identifier);
+
 		ret = -1;
 		transport_disconnect (trans);
 	}


[Index of Archives]     [Gluster Users]     [Ceph Users]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux