pndnotifyd logging was already available (just drop the -d on command line, and redir...
authorskeezix <skeezix@flotsam-vm.(none)>
Mon, 15 Feb 2010 03:31:02 +0000 (22:31 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Mon, 15 Feb 2010 03:31:02 +0000 (22:31 -0500)
 -- but now you can just add -l to command line to cause it to go go debuglevel and spit out to /tmp/pndnotifyd.log
 -- can actualyl do -l#, where # is log level, default is 0 (all)

pnd_logger now has set_buried_logging() which lets you turn on logging in libpnd API that doesn't normally log, such as
the discovery code; this way we can log some deep-shit, if we really want to

Makefile
apps/pndnotifyd.c
include/pnd_logger.h
lib/pnd_discovery.c
lib/pnd_logger.c
lib/pnd_utility.c

index 356756d..dab703e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -23,10 +23,10 @@ SOLIB1 = libpnd.so.1.0.1    # versioned name
 XMLOBJ = lib/tinyxml/tinystr.o lib/tinyxml/tinyxml.o lib/tinyxml/tinyxmlerror.o lib/tinyxml/tinyxmlparser.o
 ALLOBJ = pnd_conf.o pnd_container.o pnd_discovery.o pnd_pxml.o pnd_notify.o pnd_locate.o pnd_tinyxml.o pnd_pndfiles.o pnd_apps.o pnd_utility.o pnd_desktop.o pnd_io_gpio.o pnd_logger.o
 
-all: ${SOLIB} ${LIB} conftest discotest notifytest pndnotifyd rawpxmltest pndvalidator loggertest pnd_run pndevmapperd
+all: ${SOLIB} ${LIB} conftest discotest notifytest pndnotifyd rawpxmltest pndvalidator loggertest pnd_run pndevmapperd pnd_info
 
 clean:
-       ${RM} -f ${ALLOBJ} ${XMLOBJ} ${LIB} ${SOLIB1} locatetest.o bin/locatetest conftest.o bin/conftest discotest.o bin/discotest loggertest.o bin/loggertest bin/notifytest notifytest.o bin/rawpxmltest rawpxmltest.o bin/pnd_run pnd_run.o bin/pndevmapperd pndevmapperd.o bin/pndnotifyd pndnotifyd.o ${SOLIB} testdata/dotdesktop/*.desktop testdata/menu/*.desktop testdata/apps/*.pnd testdata/dotdesktop/*.png deployment/usr/lib/libpnd* deployment/usr/bin/pndnotifyd deployment/usr/bin/pnd_run deployment/usr/pandora/scripts/* deployment/etc/sudoers deployment/etc/init.d/pndnotifyd bin/pndvalidator pndvalidator.o deployment/usr/bin/pndevmapperd testdata/menuicons/*
+       ${RM} -f ${ALLOBJ} ${XMLOBJ} ${LIB} ${SOLIB1} locatetest.o bin/locatetest conftest.o bin/conftest discotest.o bin/discotest loggertest.o bin/loggertest bin/notifytest notifytest.o bin/rawpxmltest rawpxmltest.o bin/pnd_run pnd_run.o pnd_info.o bin/pnd_info bin/pndevmapperd pndevmapperd.o bin/pndnotifyd pndnotifyd.o ${SOLIB} testdata/dotdesktop/*.desktop testdata/menu/*.desktop testdata/apps/*.pnd testdata/dotdesktop/*.png deployment/usr/lib/libpnd* deployment/usr/bin/pndnotifyd deployment/usr/bin/pnd_run deployment/usr/bin/pnd_info deployment/usr/pandora/scripts/* deployment/etc/sudoers deployment/etc/init.d/pndnotifyd bin/pndvalidator pndvalidator.o deployment/usr/bin/pndevmapperd testdata/menuicons/*
        ${RM} -rf deployment/media
        find . -name "*~*" -exec rm {} \; -print
 
@@ -54,6 +54,9 @@ pndvalidator: pndvalidator.o ${SOLIB1}
 pnd_run:       pnd_run.o ${SOLIB1}
        ${CC} -lstdc++ -o bin/pnd_run pnd_run.o ${SOLIB1}
 
+pnd_info:      pnd_info.o ${SOLIB1}
+       ${CC} -lstdc++ -o bin/pnd_info pnd_info.o ${SOLIB1}
+
 pndevmapperd:  pndevmapperd.o ${SOLIB1}
        ${CC} -lstdc++ -o bin/pndevmapperd pndevmapperd.o ${SOLIB1}
 
index f7850df..a2ca73f 100644 (file)
@@ -79,6 +79,7 @@ int main ( int argc, char *argv[] ) {
   // behaviour
   unsigned char scanonlaunch = 1;
   unsigned int interval_secs = 5;
+  int logall = -1; // -1 means normal logging rules; >=0 means log all!
   // misc
   int i;
 
@@ -93,10 +94,24 @@ int main ( int argc, char *argv[] ) {
       interval_secs = atoi ( argv [ i ] );
     } else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'n' ) {
       scanonlaunch = 0;
+    } else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'l' ) {
+
+      if ( isdigit ( argv [ i ][ 2 ] ) ) {
+       unsigned char x = atoi ( argv [ i ] + 2 );
+       if ( x >= 0 &&
+            x < pndn_none )
+       {
+         logall = x;
+       }
+      } else {
+       logall = 0;
+      }
+
     } else {
       printf ( "%s [-d] [##]\n", argv [ 0 ] );
       printf ( "-d\tDaemon mode; detach from terminal, chdir to /tmp, suppress output. Optional.\n" );
       printf ( "-n\tDo not scan on launch; default is to run a scan for apps when %s is invoked.\n", argv [ 0 ] );
+      printf ( "-l#\tLog-it; -l is 0-and-up (or all), and -l2 means 2-and-up (not all); l[0-3] for now. Log goes to /tmp/pndnotifyd.log\n" );
       printf ( "##\tA numeric value is interpreted as number of seconds between checking for filesystem changes. Default %u.\n",
               interval_secs );
       printf ( "Signal: HUP the process to force reload of configuration and reset the notifier watch paths\n" );
@@ -107,15 +122,38 @@ int main ( int argc, char *argv[] ) {
 
   /* enable logging?
    */
-  if ( g_daemon_mode ) {
-    // nada
+  pnd_log_set_pretext ( "pndnotifyd" );
+  pnd_log_set_flush ( 1 );
+
+  if ( logall == -1 ) {
+    // standard logging; non-daemon versus daemon
+
+    if ( g_daemon_mode ) {
+      // nada
+    } else {
+      pnd_log_set_filter ( pndn_rem );
+      pnd_log_to_stdout();
+    }
+
   } else {
-    pnd_log_set_filter ( pndn_rem );
-    pnd_log_set_pretext ( "pndnotifyd" );
-    pnd_log_to_stdout();
-    pnd_log_set_flush ( 1 );
-    pnd_log ( pndn_rem, "log level starting as %u", pnd_log_get_filter() );
-  }
+    FILE *f;
+
+    f = fopen ( "/tmp/pndnotifyd.log", "w" );
+
+    if ( f ) {
+      pnd_log_set_filter ( logall );
+      pnd_log_to_stream ( f );
+      pnd_log ( pndn_rem, "logall mode - logging to /tmp/pndnotifyd.log\n" );
+    }
+
+    if ( logall == pndn_debug ) {
+      pnd_log_set_buried_logging ( 1 ); // log the shit out of it
+      pnd_log ( pndn_rem, "logall mode 0 - turned on buried logging\n" );
+    }
+
+  } // logall
+
+  pnd_log ( pndn_rem, "log level starting as %u", pnd_log_get_filter() );
 
   pnd_log ( pndn_rem, "Interval between checks is %u seconds\n", interval_secs );
 
@@ -353,8 +391,12 @@ void consume_configuration ( void ) {
     }
 
     if ( pnd_conf_get_as_int ( apph, PNDNOTIFYD_LOGLEVEL ) != PND_CONF_BADNUM ) {
-      pnd_log_set_filter ( pnd_conf_get_as_int ( apph, PNDNOTIFYD_LOGLEVEL ) );
-      pnd_log ( pndn_rem, "config file causes loglevel to change to %u", pnd_log_get_filter() );
+      if ( pnd_log_do_buried_logging() == 0 ) {
+       pnd_log_set_filter ( pnd_conf_get_as_int ( apph, PNDNOTIFYD_LOGLEVEL ) );
+       pnd_log ( pndn_rem, "config file causes loglevel to change to %u", pnd_log_get_filter() );
+      } else {
+       pnd_log ( pndn_rem, "-l command line suppresses log level change in config file\n" );
+      }
     }
 
   } else {
@@ -628,6 +670,9 @@ unsigned char perform_discoveries ( char *appspath, char *overridespath,
 {
   pnd_box_handle applist;
 
+  pnd_log ( pndn_rem, "perform discovery - apps: %s, overrides: %s\n", appspath, overridespath );
+  pnd_log ( pndn_rem, "                  - emit desktop: %s, icons: %s\n", emitdesktoppath, emiticonpath );
+
   // attempt to auto-discover applications in the given path
   applist = pnd_disco_search ( appspath, overridespath );
 
@@ -681,13 +726,13 @@ unsigned char perform_discoveries ( char *appspath, char *overridespath,
          }
        }
        if ( source_libpnd ) {
-#if 0
-         pnd_log ( pndn_rem,
+#if 1
+         pnd_log ( pndn_debug,
                    "File '%s' appears to have been created by libpnd so candidate for delete: %u\n", buffer, source_libpnd );
 #endif
        } else {
-#if 0
-         pnd_log ( pndn_rem, "File '%s' appears NOT to have been created by libpnd, so leave it alone\n", buffer );
+#if 1
+         pnd_log ( pndn_debug, "File '%s' appears NOT to have been created by libpnd, so leave it alone\n", buffer );
 #endif
          continue; // skip deleting it
        }
@@ -695,8 +740,8 @@ unsigned char perform_discoveries ( char *appspath, char *overridespath,
        // file is 'new'?
        if ( stat ( buffer, &dirs ) == 0 ) {
          if ( dirs.st_mtime >= createtime ) {
-#if 0
-           pnd_log ( pndn_rem, "File '%s' seems 'new', so leave it alone.\n", buffer );
+#if 1
+           pnd_log ( pndn_debug, "File '%s' seems 'new', so leave it alone.\n", buffer );
 #endif
            continue; // skip deleting it
          }
index 6db1aed..349593e 100644 (file)
@@ -41,6 +41,12 @@ unsigned char pnd_log_get_filter ( void );
 // how many targets can be opened, entirely? this is a compile time limit, for sanity.
 unsigned char pnd_log_max_targets ( void );
 
+// tell buried lib functions to do some logging here; ie: since not all API's have a 'options' type flag where we could
+// add a hint to begin logging, they can just ask the logger if they need to do it
+#define PND_LOG_DEFAULT 0 // level 0 is by default the 'debug' level, with anything higher non-debug; only used for buried logging
+void pnd_log_set_buried_logging ( unsigned char yesno ); // set 1 for 'yes', 0 for 'no'
+unsigned char pnd_log_do_buried_logging ( void ); // return 1 for 'yes'
+
 #ifdef __cplusplus
 } /* "C" */
 #endif
index f788065..594a03e 100644 (file)
@@ -16,6 +16,7 @@
 #include "pnd_pathiter.h"
 #include "pnd_apps.h"
 #include "pnd_pndfiles.h"
+#include "pnd_logger.h"
 
 // need these 'globals' due to the way nftw and ftw work :/
 static pnd_box_handle disco_box;
@@ -47,12 +48,17 @@ static int pnd_disco_callback ( const char *fpath, const struct stat *sb,
   unsigned char valid = pnd_object_type_unknown;
   pnd_pxml_handle pxmlh = 0;
   unsigned int pxml_close_pos = 0;
+  unsigned char logit = pnd_log_do_buried_logging();
 
-  //printf ( "disco root callback encountered '%s'\n", fpath );
+  if ( logit ) {
+    pnd_log ( PND_LOG_DEFAULT, "disco callback encountered '%s'\n", fpath );
+  }
 
   // PXML.xml is a possible application candidate (and not a dir named PXML.xml :)
   if ( typeflag & FTW_D ) {
-    //printf ( " .. is dir, skipping\n" );
+    if ( logit ) {
+      pnd_log ( PND_LOG_DEFAULT, " .. is dir, skipping\n" );
+    }
     return ( 0 ); // skip directories and other non-regular files
   }
 
@@ -66,7 +72,9 @@ static int pnd_disco_callback ( const char *fpath, const struct stat *sb,
 
   // if not a file of interest, just keep looking until we run out
   if ( ! valid ) {
-    //printf ( " .. bad filename, skipping\n" );
+    if ( logit ) {
+      pnd_log ( PND_LOG_DEFAULT, " .. bad filename, skipping\n" );
+    }
     return ( 0 );
   }
 
index 96b3e3f..38a6586 100644 (file)
@@ -105,7 +105,7 @@ unsigned char pnd_log_max_targets ( void ) {
   return ( PND_LOG_MAX );
 }
 
-void pnd_log_emit ( char *message ) {
+static void pnd_log_emit ( unsigned char level, char *message ) {
   unsigned char i;
 
   // iterate across targets and attempt to emit
@@ -118,9 +118,13 @@ void pnd_log_emit ( char *message ) {
       break;
 
     case pndl_stream:
+      // pretext
       if ( log_pretext ) {
        fprintf ( log_targets [ i ].stream, "%s\t", log_pretext );
       }
+      // log level
+      fprintf ( log_targets [ i ].stream, "%u\t", level );
+      // message
       if ( message ) {
        fprintf ( log_targets [ i ].stream, "%s", message );
        if ( strchr ( message, '\n' ) == NULL ) {
@@ -173,7 +177,7 @@ unsigned char pnd_log ( unsigned char level, char *fmt, ... ) {
 
     /* If that worked, return the string. */
     if ( n > -1 && n < size ) {
-      pnd_log_emit ( p );
+      pnd_log_emit ( level, p );
       break;
     }
 
@@ -197,3 +201,17 @@ unsigned char pnd_log ( unsigned char level, char *fmt, ... ) {
 
   return ( 1 );
 }
+
+
+static unsigned char _do_buried_logging = 0;
+void pnd_log_set_buried_logging ( unsigned char yesno ) {
+  _do_buried_logging = yesno;
+  return;
+}
+
+unsigned char pnd_log_do_buried_logging ( void ) {
+  if ( _do_buried_logging == 1 ) {
+    return ( 1 );
+  }
+  return ( 0 );
+}
index 33b60ef..5009b51 100644 (file)
@@ -67,8 +67,8 @@ char *pnd_expand_tilde ( char *freeable_buffer ) {
   char *s = freeable_buffer;
   char *home = getenv ( "HOME" );
 
-  printf ( "DEBUG: expand tilde IN: '%s'\n", freeable_buffer );
-  printf ( "DEBUG:  $HOME was %s\n", home );
+  //printf ( "DEBUG: expand tilde IN: '%s'\n", freeable_buffer );
+  //printf ( "DEBUG:  $HOME was %s\n", home );
 
   // well, as pndnotifyd (etc) may be running as _root_, while the user is logged in
   // as 'pandora' or god knows what, this could be problematic. Other parts of the lib
@@ -106,7 +106,7 @@ char *pnd_expand_tilde ( char *freeable_buffer ) {
              florp = strdup ( pw -> pw_dir );
 
              home = florp;
-             printf ( "  DEBUG: home (for %s) is %s (from %u)\n", b.ut_user, home, b.ut_type );
+             //printf ( "  DEBUG: home (for %s) is %s (from %u)\n", b.ut_user, home, b.ut_type );
 
            } // passwd entry matches the utmp entry
 
@@ -126,10 +126,10 @@ char *pnd_expand_tilde ( char *freeable_buffer ) {
     return ( s ); // can't succeed
   }
 
-  printf ( "DEBUG: entering while (%s) with home (%s)\n", s, home );
+  //printf ( "DEBUG: entering while (%s) with home (%s)\n", s, home );
 
   while ( ( p = strchr ( s, '~' ) ) ) {
-    printf ( "DEBUG: within while (%s)\n", s );
+    //printf ( "DEBUG: within while (%s)\n", s );
     char *temp = malloc ( strlen ( s ) + strlen ( home ) + 1 );
     memset ( temp, '\0', strlen ( s ) + strlen ( home ) + 1 );
     // copy in stuff prior to ~
@@ -143,7 +143,7 @@ char *pnd_expand_tilde ( char *freeable_buffer ) {
     s = temp;
   } // while finding matches
 
-  printf ( "DEBUG: expand tilde OUT: '%s'\n", s );
+  //printf ( "DEBUG: expand tilde OUT: '%s'\n", s );
 
   return ( s );
 }