OSDN Git Service

Adds an hb_deep_log() function for multiple levels of debugging verbosity. Level...
authorjbrjake <jbrjake@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Thu, 9 Oct 2008 00:16:14 +0000 (00:16 +0000)
committerjbrjake <jbrjake@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Thu, 9 Oct 2008 00:16:14 +0000 (00:16 +0000)
git-svn-id: svn://localhost/HandBrake/trunk@1819 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/common.c
libhb/hb.c
libhb/internal.h
test/test.c

index f0ad9e4..073abb9 100644 (file)
@@ -549,6 +549,44 @@ void hb_log( char * log, ... )
     fprintf( stderr, "%s", string );
 }
 
+int global_verbosity_level; //Necessary for hb_deep_log
+/**********************************************************************
+ * hb_deep_log
+ **********************************************************************
+ * If verbose mode is >= level, print message with timestamp. Messages
+ * longer than 360 characters are stripped ;p
+ *********************************************************************/
+void hb_deep_log( hb_debug_level_t level, char * log, ... )
+{
+    char        string[362]; /* 360 chars + \n + \0 */
+    time_t      _now;
+    struct tm * now;
+    va_list     args;
+
+    if( global_verbosity_level < level )
+    {
+        /* Hiding message */
+        return;
+    }
+
+    /* Get the time */
+    _now = time( NULL );
+    now  = localtime( &_now );
+    sprintf( string, "[%02d:%02d:%02d] ",
+             now->tm_hour, now->tm_min, now->tm_sec );
+
+    /* Convert the message to a string */
+    va_start( args, log );
+    vsnprintf( string + 11, 349, log, args );
+    va_end( args );
+
+    /* Add the end of line */
+    strcat( string, "\n" );
+
+    /* Print it */
+    fprintf( stderr, "%s", string );
+}
+
 /**********************************************************************
  * hb_error
  **********************************************************************
index 390e566..06b4893 100644 (file)
@@ -69,11 +69,10 @@ hb_handle_t * hb_init_real( int verbose, int update_check )
     hb_handle_t * h = calloc( sizeof( hb_handle_t ), 1 );
     uint64_t      date;
 
-    /* See hb_log() in common.c */
-    if( verbose > HB_DEBUG_NONE )
-    {
+    /* See hb_deep_log() and hb_log() in common.c */
+    global_verbosity_level = verbose;
+    if( verbose )
         putenv( "HB_DEBUG=1" );
-    }
 
     /* Check for an update on the website if asked to */
     h->build = -1;
index e9828fd..5d7f654 100644 (file)
@@ -8,6 +8,14 @@
  * common.c
  **********************************************************************/
 void hb_log( char * log, ... );
+extern int global_verbosity_level; // Global variable for hb_deep_log
+typedef enum hb_debug_level_s
+{
+    HB_SUPPORT_LOG     = 1, // Logging helpful in tech support
+    HB_MEMORY_LOG      = 2, // logging about memory usage
+    HB_GRANULAR_LOG    = 3  // logging on sample-by-sample
+} hb_debug_level_t;
+void hb_deep_log( hb_debug_level_t level, char * log, ... );
 void hb_error( char * fmt, ...);
 
 int  hb_list_bytes( hb_list_t * );
index da870c2..0357001 100644 (file)
@@ -1467,7 +1467,7 @@ static void ShowHelp()
        "### General Handbrake Options------------------------------------------------\n\n"
     "    -h, --help              Print help\n"
     "    -u, --update            Check for updates and exit\n"
-    "    -v, --verbose           Be verbose\n"
+    "    -v, --verbose <#>       Be verbose (optional argument: logging level)\n"
     "    -C, --cpu               Set CPU count (default: autodetected)\n"
     "    -Z. --preset <string>   Use a built-in preset. Capitalization matters, and\n"
     "                            if the preset name has spaces, surround it with\n"
@@ -1661,7 +1661,7 @@ static int ParseOptions( int argc, char ** argv )
           {
             { "help",        no_argument,       NULL,    'h' },
             { "update",      no_argument,       NULL,    'u' },
-            { "verbose",     no_argument,       NULL,    'v' },
+            { "verbose",     optional_argument, NULL,    'v' },
             { "cpu",         required_argument, NULL,    'C' },
 
             { "format",      required_argument, NULL,    'f' },
@@ -1719,7 +1719,7 @@ static int ParseOptions( int argc, char ** argv )
         int c;
 
                c = getopt_long( argc, argv,
-                                                "hvuC:f:4i:Io:t:Lc:m::a:6:s:UFN:e:E:2dD:7895gpOP::w:l:n:b:q:S:B:r:R:Qx:TY:X:Z:z",
+                                                "hv::uC:f:4i:Io:t:Lc:m::a:6:s:UFN:e:E:2dD:7895gpOP::w:l:n:b:q:S:B:r:R:Qx:TY:X:Z:z",
                          long_options, &option_index );
         if( c < 0 )
         {
@@ -1735,7 +1735,14 @@ static int ParseOptions( int argc, char ** argv )
                 update = 1;
                 break;
             case 'v':
-                debug = HB_DEBUG_ALL;
+                if( optarg != NULL )
+                {
+                    debug = atoi( optarg );
+                }
+                else
+                {
+                    debug = 1;
+                }
                 break;
             case 'C':
                 cpu = atoi( optarg );