From: Alexandru C. <cs...@us...> - 2006-02-27 22:20:53
|
Update of /cvsroot/groundstation/grig2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30939 Modified Files: grig-debug.c grig-debug.h Log Message: Implemented logging source but there is no code to explicitly save to log file. The messages are printed to stderr, so the log can be saved that way. Index: grig-debug.c =================================================================== RCS file: /cvsroot/groundstation/grig2/src/grig-debug.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** grig-debug.c 27 Feb 2006 16:41:05 -0000 1.2 --- grig-debug.c 27 Feb 2006 22:20:45 -0000 1.3 *************** *** 40,43 **** --- 40,45 ---- #include <glib.h> #include <glib/gi18n.h> + #include <time.h> + #include <sys/time.h> #include <hamlib/rig.h> #ifdef HAVE_CONFIG_H *************** *** 47,54 **** --- 49,67 ---- + + static gchar *logfname = NULL; static GIOChannel *logfile = NULL; + const gchar *SRC_TO_STR[] = {N_("NONE"), N_("HAMLIB"), N_("GRIG")}; + + + static void manage_debug_message (debug_msg_src_t source, + enum rig_debug_level_e debug_level, + const gchar *message); + + + /** \brief Initialise debug handler * \param filename File name of log file or NULL. *************** *** 69,73 **** /* set debug handler */ ! rig_set_debug_callback (grig_debug_cb, NULL); /* send debug message to indicate readiness of debug handler */ --- 82,86 ---- /* set debug handler */ ! rig_set_debug_callback (grig_debug_hamlib_cb, NULL); /* send debug message to indicate readiness of debug handler */ *************** *** 102,110 **** int ! grig_debug_cb (enum rig_debug_level_e debug_level, ! rig_ptr_t user_data, ! const char *fmt, ! va_list ap) { --- 115,125 ---- + + /** \brief Manage hamlib debug messages */ int ! grig_debug_hamlib_cb (enum rig_debug_level_e debug_level, ! rig_ptr_t user_data, ! const char *fmt, ! va_list ap) { *************** *** 113,117 **** guint numlines; /* the number of lines in the message */ guint i; - GTimeVal curtime; /* current time (same as struct timeval) */ --- 128,131 ---- *************** *** 127,141 **** numlines = g_strv_length (msgv); - g_print ("%d: %s\n", debug_level, msg); g_free (msg); ! /* get the time */ ! g_get_current_time (&curtime); ! /* for each line in msgv, print the line to stderr ! and save into logfile. */ for (i = 0; i < numlines; i++) { } --- 141,188 ---- numlines = g_strv_length (msgv); g_free (msg); + /* for each line in msgv, call the real debug handler + which will print the debug message and save it to + a logfile + */ + for (i = 0; i < numlines; i++) { + manage_debug_message (MSG_SRC_HAMLIB, debug_level, msgv[i]); + } + ! g_strfreev (msgv); ! ! return RIG_OK; ! } ! ! int ! grig_debug_local (enum rig_debug_level_e debug_level, ! const gchar *msg) ! { ! gchar **msgv; /* debug message line by line */ ! gchar *locmsg; ! guint numlines; /* the number of lines in the message */ ! guint i; ! ! ! locmsg = g_strdup (msg); ! ! /* remove trailing \n */ ! g_strchomp (locmsg); ! ! /* split the message in case it is a multiline message */ ! msgv = g_strsplit_set (locmsg, "\n", 0); ! numlines = g_strv_length (msgv); ! ! g_free (locmsg); ! ! /* for each line in msgv, call the real debug handler ! which will print the debug message and save it to ! a logfile */ for (i = 0; i < numlines; i++) { + manage_debug_message (MSG_SRC_GRIG, debug_level, msgv[i]); } *************** *** 148,151 **** --- 195,199 ---- + /** \brief Get the name of the current log file. * \return The name of the current log file or NULL. *************** *** 166,167 **** --- 214,256 ---- } } + + + + + /***** FIXME: portability issues because of time? */ + /***** FIXME: size management sucks */ + static void + manage_debug_message (debug_msg_src_t source, + enum rig_debug_level_e debug_level, + const gchar *message) + { + gchar msg_time[50]; + guint size; + struct timeval tval; + struct timezone tzone; + time_t t; + gint x; + + + /* get the time */ + x = gettimeofday (&tval, &tzone); + t = (time_t ) tval.tv_sec; + size = strftime (msg_time, 48, "%Y/%m/%d %H:%M:%S", localtime (&t)); + if (size < 49) { + msg_time[size] = '\0'; + } + else { + msg_time[49] = '\0'; + } + + g_fprintf (stderr, + "%s%s%s%s%d%s%s\n", + msg_time, + GRIG_DEBUG_SEPARATOR, + SRC_TO_STR[source], + GRIG_DEBUG_SEPARATOR, + debug_level, + GRIG_DEBUG_SEPARATOR, + message); + + } Index: grig-debug.h =================================================================== RCS file: /cvsroot/groundstation/grig2/src/grig-debug.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** grig-debug.h 27 Feb 2006 16:26:47 -0000 1.1 --- grig-debug.h 27 Feb 2006 22:20:45 -0000 1.2 *************** *** 36,45 **** ! void grig_debug_init (gchar *filename); ! void grig_debug_close (void); ! int grig_debug_cb (enum rig_debug_level_e debug_level, ! rig_ptr_t user_data, ! const char *fmt, ! va_list ap); gchar *grig_debug_get_log_file (void); --- 36,59 ---- ! #define GRIG_DEBUG_SEPARATOR "\t" ! ! /** \brief Debug message sources. */ ! typedef enum { ! MSG_SRC_NONE = 0, /*!< No source, unknown source. */ ! MSG_SRC_HAMLIB = 1, /*!< Debug message comes from hamlib */ ! MSG_SRC_GRIG = 2 /*!< Debug message comes from grig itself */ ! } debug_msg_src_t; ! ! ! ! void grig_debug_init (gchar *filename); ! void grig_debug_close (void); ! int grig_debug_hamlib_cb (enum rig_debug_level_e debug_level, ! rig_ptr_t user_data, ! const char *fmt, ! va_list ap); ! ! int grig_debug_local (enum rig_debug_level_e debug_level, ! const gchar *msg); gchar *grig_debug_get_log_file (void); |