[xiph-cvs] cvs commit: log log.c log.h

Michael Smith msmith at xiph.org
Tue Jan 29 01:20:28 PST 2002



msmith      02/01/29 01:20:28

  Modified:    conf     ices-live.xml ices-playlist.xml
               src      config.c config.h ices.c
               .        log.c log.h
  Log:
  Allow logging to go to stderr instead of to a file, if the user so chooses
  (example configs turn this off, to leave behaviour as it was).

Revision  Changes    Path
1.3       +1 -0      ices/conf/ices-live.xml

Index: ices-live.xml
===================================================================
RCS file: /usr/local/cvsroot/ices/conf/ices-live.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ices-live.xml	2002/01/28 00:19:14	1.2
+++ ices-live.xml	2002/01/29 09:20:26	1.3
@@ -5,6 +5,7 @@
         <logpath>/tmp</logpath> <!-- where logs, etc go. -->
         <logfile>ices.log</logfile>
         <loglevel>4</loglevel> <!-- 1=error,2=warn,3=info,4=debug -->
+    <consolelog>0</consolelog> <!-- logfile is ignored if this is set to 1 -->
 
         <stream>
                 <!-- metadata used for stream listing (not currently used) -->

<p><p>1.4       +2 -0      ices/conf/ices-playlist.xml

Index: ices-playlist.xml
===================================================================
RCS file: /usr/local/cvsroot/ices/conf/ices-playlist.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ices-playlist.xml	2002/01/28 00:19:14	1.3
+++ ices-playlist.xml	2002/01/29 09:20:26	1.4
@@ -5,6 +5,8 @@
         <logpath>/tmp</logpath> <!-- where logs, etc go. -->
         <logfile>ices.log</logfile>
         <loglevel>4</loglevel> <!-- 1=error,2=warn,3=info,4=debug -->
+    <consolelog>0</consolelog> <!-- set this to 1 to log to the console instead
+                                    of to the file above -->
 
         <stream>
                 <!-- metadata used for stream listing (not currently used) -->

<p><p>1.6       +5 -1      ices/src/config.c

Index: config.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/config.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- config.c	2002/01/28 12:52:58	1.5
+++ config.c	2002/01/29 09:20:27	1.6
@@ -1,7 +1,7 @@
 /* config.c
  * - config file reading code, plus default settings.
  *
- * $Id: config.c,v 1.5 2002/01/28 12:52:58 msmith Exp $
+ * $Id: config.c,v 1.6 2002/01/29 09:20:27 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -30,6 +30,7 @@
 #define DEFAULT_LOGPATH "/tmp"
 #define DEFAULT_LOGFILE "ices.log"
 #define DEFAULT_LOGLEVEL 1
+#define DEFAULT_LOG_STDERR 1
 #define DEFAULT_STREAM_NAME "unnamed ices stream"
 #define DEFAULT_STREAM_GENRE "ices unset"
 #define DEFAULT_STREAM_DESCRIPTION "no description set"
@@ -294,6 +295,8 @@
                         SET_STRING(config->logfile);
                 else if (strcmp(node->name, "loglevel") == 0)
                         SET_INT(config->loglevel);
+        else if (strcmp(node->name, "consolelog") == 0)
+            SET_INT(config->log_stderr);
                 else if (strcmp(node->name, "stream") == 0)
                         _parse_stream(config, doc, node->xmlChildrenNode);
         } while ((node = node->next));
@@ -307,6 +310,7 @@
         c->logpath = strdup(DEFAULT_LOGPATH);
         c->logfile = strdup(DEFAULT_LOGFILE);
         c->loglevel = DEFAULT_LOGLEVEL;
+    c->log_stderr = DEFAULT_LOG_STDERR;
 
         c->stream_name = strdup(DEFAULT_STREAM_NAME);
         c->stream_genre = strdup(DEFAULT_STREAM_GENRE);

<p><p>1.10      +2 -1      ices/src/config.h

Index: config.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/config.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- config.h	2002/01/28 00:19:15	1.9
+++ config.h	2002/01/29 09:20:27	1.10
@@ -1,7 +1,7 @@
 /* config.h
  * - configuration, and global structures built from config
  *
- * $Id: config.h,v 1.9 2002/01/28 00:19:15 msmith Exp $
+ * $Id: config.h,v 1.10 2002/01/29 09:20:27 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -67,6 +67,7 @@
         char *logpath;
         char *logfile;
         int loglevel;
+    int log_stderr;
 
         /* <stream> */
 

<p><p>1.4       +8 -12     ices/src/ices.c

Index: ices.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/ices.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ices.c	2001/11/09 08:14:50	1.3
+++ ices.c	2002/01/29 09:20:27	1.4
@@ -1,9 +1,9 @@
 /* ices.c
  * - Main startup, thread launching, and cleanup code.
  *
- * $Id: ices.c,v 1.3 2001/11/09 08:14:50 msmith Exp $
+ * $Id: ices.c,v 1.4 2002/01/29 09:20:27 msmith Exp $
  *
- * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
+ * Copyright (c) 2001-2002 Michael Smith <msmith at labyrinth.net.au>
  *
  * This program is distributed under the terms of the GNU General
  * Public License, version 2. You may use, modify, and redistribute
@@ -35,7 +35,7 @@
         if (argc != 2) 
         {
                 fprintf(stderr, "IceS version 2.0beta1\n"
-				"  (c) Copyright 2001 Michael Smith <msmith at icecast.org>\n"
+				"  (c) Copyright 2001-2002 Michael Smith <msmith at icecast.org>\n"
                                 "\n"
                                 "Usage: \"ices config.xml\"\n");
                 return 1;
@@ -60,7 +60,10 @@
 
         snprintf(logpath, FILENAME_MAX, "%s/%s", ices_config->logpath, 
                         ices_config->logfile);
-	log = log_open(logpath);
+    if(ices_config->log_stderr)
+        log = log_open_file(stderr);
+    else
+	    log = log_open(logpath);
         /* Set the log level, if requested - defaults to 2 (WARN) otherwise */
         if (ices_config->loglevel)
                 log_set_level(log, ices_config->loglevel);
@@ -73,8 +76,8 @@
         input_loop();
 
         LOG_INFO0("Shutdown complete");
-	log_close(log);
 
+	log_close(log);
 
  fail:
         config_shutdown();
@@ -84,12 +87,5 @@
 
         return 0;
 }
-
-
-
-
-
-
-
 
 

<p><p>1.6       +24 -8     log/log.c

Index: log.c
===================================================================
RCS file: /usr/local/cvsroot/log/log.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- log.c	2001/11/10 04:47:25	1.5
+++ log.c	2002/01/29 09:20:27	1.6
@@ -69,27 +69,43 @@
         _initialized = 1;
 }
 
-int log_open(const char *filename)
+int log_open_file(FILE *file)
 {
-	int log_id;
+    int log_id;
 
-	if (filename == NULL) return LOG_EINSANE;
-	if (strcmp(filename, "") == 0) return LOG_EINSANE;
+    if(file == NULL) return LOG_EINSANE;
 
         log_id = _get_log_id();
         if (log_id < 0) return LOG_ENOMORELOGS;
 
-	loglist[log_id].logfile = fopen(filename, "a");
+	loglist[log_id].logfile = file;
         if (loglist[log_id].logfile != NULL) {
-		loglist[log_id].filename = (char *)strdup(filename);
+		loglist[log_id].filename = NULL;
         } else {
                 _release_log_id(log_id);
                 return LOG_ECANTOPEN;
         }
 
-	setvbuf(loglist[log_id].logfile, NULL, _IOLBF, 0);
-
         return log_id;
+}
+
+
+int log_open(const char *filename)
+{
+	int ret;
+    FILE *file;
+
+	if (filename == NULL) return LOG_EINSANE;
+	if (strcmp(filename, "") == 0) return LOG_EINSANE;
+    
+    file = fopen(filename, "a");
+
+    ret = log_open_file(file);
+
+	if(ret >= 0)
+        setvbuf(file, NULL, _IOLBF, 0);
+
+    return ret;
 }
 
 int log_open_with_buffer(const char *filename, int size)

<p><p>1.3       +3 -0      log/log.h

Index: log.h
===================================================================
RCS file: /usr/local/cvsroot/log/log.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- log.h	2001/10/20 16:47:01	1.2
+++ log.h	2002/01/29 09:20:28	1.3
@@ -1,6 +1,8 @@
 #ifndef __LOG_H__
 #define __LOG_H__
 
+#include <stdio.h>
+
 #define LOG_EINSANE -1
 #define LOG_ENOMORELOGS -2
 #define LOG_ECANTOPEN -3
@@ -9,6 +11,7 @@
 
 
 void log_initialize();
+int log_open_file(FILE *file);
 int log_open(const char *filename);
 int log_open_with_buffer(const char *filename, int size);
 void log_set_level(int log_id, int level);

<p><p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list