]> sjero.net Git - linphone/commitdiff
add an option to write logs into a file supplied from command line (--logfile)
authorSimon Morlat <simon.morlat@linphone.org>
Wed, 4 May 2011 16:59:28 +0000 (18:59 +0200)
committerSimon Morlat <simon.morlat@linphone.org>
Wed, 4 May 2011 16:59:28 +0000 (18:59 +0200)
configure.ac
gtk/linphone.h
gtk/logging.c
gtk/main.c
mediastreamer2

index 06303cc27c730a09223e2db6fdde7db0363e1e72..562ba97e023f4f0b3cc12cf1eb8c12e0c89802f8 100644 (file)
@@ -384,8 +384,9 @@ AC_ARG_ENABLE(strict,
        strictness="${enableval}"],[strictness=yes]
 )
 
+STRICT_OPTIONS="-Wall "
+
 if test "$GCC$strictness" = "yesyes" ; then
-       STRICT_OPTIONS="-Wall "
        STRICT_OPTIONS="$STRICT_OPTIONS -Werror"
        CFLAGS="$CFLAGS -fno-strict-aliasing"
 fi
index d726c0db1e7915c7e97b5de48de0ad25f396ec42..f76f1b6a8348286ae046787642fd2eaed0e30e5e 100644 (file)
@@ -108,3 +108,7 @@ void linphone_gtk_enable_transfer_button(LinphoneCore *lc, gboolean value);
 void linphone_gtk_show_login_frame(LinphoneProxyConfig *cfg);
 void linphone_gtk_exit_login_frame(void);
 void linphone_gtk_set_ui_config(const char *key, const char *value);
+
+void linphone_gtk_log_uninit();
+
+
index 5223080689a5df86399ed5a3daacc3d7676d3c51..ebadeedfc0e0aab079b6a6155f6b4baeedf47c9d 100644 (file)
@@ -24,10 +24,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include <sys/types.h>
 #endif
 
+extern gchar *linphone_logfile;
 
 static GtkWidget *log_window=NULL;
 static GStaticMutex log_mutex=G_STATIC_MUTEX_INIT;
 static GList *log_queue=NULL;
+static const char *dateformat="%Y%m%d-%H:%M:%S";
 
 #define LOG_MAX_CHARS 1000000  /*1 mega bytes of traces*/
 
@@ -54,7 +56,7 @@ static FILE *_logfile = NULL;
 
 /* Called on exit, print out the marker, close the file and avoid to
    continue logging. */
-static void linphone_gtk_log_uninit()
+void linphone_gtk_log_uninit()
 {
        if (_logfile != NULL) {
                fprintf(_logfile, "%s\n", LOGFILE_MARKER_STOP);
@@ -72,10 +74,13 @@ static FILE *linphone_gtk_log_init()
        static char _logdir[1024];
        static char _logfname[1024];
        static gboolean _log_init = FALSE;
-       const char *dst_fname;
+       const char *dst_fname=NULL;
 
        if (!_log_init) {
-               dst_fname = linphone_gtk_get_ui_config("logfile",NULL);
+               if (linphone_gtk_get_core()!=NULL){
+                       dst_fname = linphone_gtk_get_ui_config("logfile",NULL);
+                       dateformat=linphone_gtk_get_ui_config("logfile_date_format",dateformat);
+               }
                /* For anything to happen, we need a logfile configuration variable,
                 this is our trigger */
                if (dst_fname) {
@@ -101,51 +106,55 @@ static FILE *linphone_gtk_log_init()
                        }
 #define PATH_SEPARATOR '/'
 #endif
-                       /* We have a directory, fix the path to the log file in it and
-                        open the file so that we will be appending to it. */
                        if (_logdir[0] != '\0') {
-                               snprintf(_logfname, sizeof(_logfname), "%s%c%s",
-                                       _logdir, PATH_SEPARATOR, dst_fname);
-                               /* If the constant LOGFILE_ROTATION is greater than zero, then
-                                we kick away a simple rotation that will ensure that there
-                                are never more than LOGFILE_ROTATION+1 old copies of the
-                                log file on the disk.  The oldest file is always rotated
-                                "away" as expected.  Rotated files have the same name as
-                                the main log file, though with a number 0..LOGFILE_ROTATION
-                                at the end, where the greater the number is, the older the
-                                file is. */
-                               if (ortp_file_exist(_logfname)==0 && LOGFILE_ROTATION > 0) {
-                                       int i;
-                                       char old_fname[1024];
-                                       char new_fname[1024];
-
-                                       /* Rotate away existing files.  We make sure to remove the
-                                        old files otherwise rename() would not work properly.  We
-                                        have to loop in reverse here. */
-                                       for (i=LOGFILE_ROTATION-1;i>=0;i--) {
-                                               snprintf(old_fname, sizeof(old_fname), "%s%c%s.%d",
-                                                       _logdir, PATH_SEPARATOR, dst_fname, i);
-                                               snprintf(new_fname, sizeof(new_fname), "%s%c%s.%d",
-                                                       _logdir, PATH_SEPARATOR, dst_fname, i+1);
-                                               if (ortp_file_exist(old_fname)==0) {
-                                                       if (ortp_file_exist(new_fname)==0)
-                                                               unlink(new_fname);
-                                                       rename(old_fname, new_fname);
-                                               }
-                                       }
-                                       /* Move current log file as the first of the rotation.  Make
-                                        sure to remove the old .0 also, since otherwise rename()
-                                        would not work as expected. */
+                               /* We have a directory, fix the path to the log file in it and
+                                open the file so that we will be appending to it. */
+                               snprintf(_logfname, sizeof(_logfname), "%s%c%s",_logdir, PATH_SEPARATOR, dst_fname);
+                       }
+               }else if (linphone_logfile!=NULL){
+                       snprintf(_logfname,sizeof(_logfname),"%s",linphone_logfile);
+               }
+               
+               if (_logfname[0]!='\0'){
+                       /* If the constant LOGFILE_ROTATION is greater than zero, then
+                        we kick away a simple rotation that will ensure that there
+                        are never more than LOGFILE_ROTATION+1 old copies of the
+                        log file on the disk.  The oldest file is always rotated
+                        "away" as expected.  Rotated files have the same name as
+                        the main log file, though with a number 0..LOGFILE_ROTATION
+                        at the end, where the greater the number is, the older the
+                        file is. */
+                       if (ortp_file_exist(_logfname)==0 && LOGFILE_ROTATION > 0) {
+                               int i;
+                               char old_fname[1024];
+                               char new_fname[1024];
+
+                               /* Rotate away existing files.  We make sure to remove the
+                                old files otherwise rename() would not work properly.  We
+                                have to loop in reverse here. */
+                               for (i=LOGFILE_ROTATION-1;i>=0;i--) {
+                                       snprintf(old_fname, sizeof(old_fname), "%s%c%s.%d",
+                                               _logdir, PATH_SEPARATOR, dst_fname, i);
                                        snprintf(new_fname, sizeof(new_fname), "%s%c%s.%d",
-                                               _logdir, PATH_SEPARATOR, dst_fname, 0);
-                                       if (ortp_file_exist(new_fname)==0)
-                                               unlink(new_fname);
-                                       rename(_logfname, new_fname);
+                                               _logdir, PATH_SEPARATOR, dst_fname, i+1);
+                                       if (ortp_file_exist(old_fname)==0) {
+                                               if (ortp_file_exist(new_fname)==0)
+                                                       unlink(new_fname);
+                                               rename(old_fname, new_fname);
+                                       }
                                }
-                               /* Start a new log file and mark that we have now initialised */
-                               _logfile = fopen(_logfname, "w");
-                               fprintf(_logfile, "%s\n", LOGFILE_MARKER_START);
+                               /* Move current log file as the first of the rotation.  Make
+                                sure to remove the old .0 also, since otherwise rename()
+                                would not work as expected. */
+                               snprintf(new_fname, sizeof(new_fname), "%s%c%s.%d",
+                                       _logdir, PATH_SEPARATOR, dst_fname, 0);
+                               if (ortp_file_exist(new_fname)==0)
+                                       unlink(new_fname);
+                               rename(_logfname, new_fname);
                        }
+                       /* Start a new log file and mark that we have now initialised */
+                       _logfile = fopen(_logfname, "w");
+                       fprintf(_logfile, "%s\n", LOGFILE_MARKER_START);
                }
                _log_init = TRUE;
        }
@@ -154,33 +163,18 @@ static FILE *linphone_gtk_log_init()
 
 static void linphone_gtk_log_file(OrtpLogLevel lev, const char *msg)
 {
-       LinphoneCore *lc;
        time_t now;
        FILE *outlog;
 
-       lc = linphone_gtk_get_core();
-       /* Nothing to do until the core has initialised */
-       if (lc == NULL)
-               return;
-
-       /* lc->config will turn NULL at exit, close the file to flush and
-        return to stop logging */
-       if (linphone_core_get_config(lc) == NULL) {
-               linphone_gtk_log_uninit();
-               return;
-       }
-
        outlog = linphone_gtk_log_init();
        if (outlog != NULL) {
                /* We have an opened file and we have initialised properly, it's
                 time to write all these log messages. We convert the log level
                 from oRTP into something readable and timestamp each log
-                message.  The format of the timestamp can be controlled by
+                message.  The format of the time       stamp can be controlled by
                 logfile_date_format in the GtkUi section of the config file,
                 but it defaults to something compact, but yet readable. */
                const char *lname="undef";
-               const char *dateformat=linphone_gtk_get_ui_config("logfile_date_format",
-                   "%Y%m%d-%H:%M:%S");
                char date[256];
 
                /* Convert level constant to text */
index 9adec52e8162edcb352fc8d15b449bbe67d1ffcd..622feca0dde3826af2048dc40bff456a80a6b450 100644 (file)
@@ -64,6 +64,7 @@ static gchar * addr_to_call = NULL;
 static gboolean iconified=FALSE;
 static gchar *workingdir=NULL;
 static char *progpath=NULL;
+gchar *linphone_logfile=NULL;
 
 static GOptionEntry linphone_options[]={
        {
@@ -73,6 +74,13 @@ static GOptionEntry linphone_options[]={
                .arg_data= (gpointer)&verbose,
                .description=N_("log to stdout some debug information while running.")
        },
+       {
+           .long_name = "logfile",
+           .short_name = 'l',
+           .arg = G_OPTION_ARG_STRING,
+           .arg_data = &linphone_logfile,
+           .description = N_("path to a file to write logs into.")
+       },
        {
                .long_name="iconified",
                .short_name= '\0',
@@ -1492,6 +1500,7 @@ int main(int argc, char *argv[]){
        gdk_threads_leave();
        linphone_gtk_destroy_log_window();
        linphone_core_destroy(the_core);
+       linphone_gtk_log_uninit();
 #ifndef HAVE_GTK_OSX
        /*workaround a bug on win32 that makes status icon still present in the systray even after program exit.*/
        gtk_status_icon_set_visible(icon,FALSE);
index bbde91a403ae91f115058ff0ed9de90137d0b6f9..c73bc0d25b29ee535c687869d7c98a69d805d1f0 160000 (submodule)
@@ -1 +1 @@
-Subproject commit bbde91a403ae91f115058ff0ed9de90137d0b6f9
+Subproject commit c73bc0d25b29ee535c687869d7c98a69d805d1f0