diff options
author | jstebbins <[email protected]> | 2011-06-15 16:38:13 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2011-06-15 16:38:13 +0000 |
commit | 4d7216fba8652a83821be49cd16cc851b5cc4cd2 (patch) | |
tree | e809a93e3606ebc118f12e75b88fc15fced54bcb | |
parent | 74dd3640936fe30a7be562615a997c30ebe5acb0 (diff) |
libhb: fix a warning in decssasub.c by adding new hb_valog function
And consolidate logging code in hb_valog. hb_log and hb_deep_log
call hb_valog.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4060 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | libhb/common.c | 70 | ||||
-rw-r--r-- | libhb/decssasub.c | 11 | ||||
-rw-r--r-- | libhb/internal.h | 1 |
3 files changed, 40 insertions, 42 deletions
diff --git a/libhb/common.c b/libhb/common.c index 5f3ce49f8..2b2917e5d 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -852,18 +852,18 @@ void hb_list_close( hb_list_t ** _l ) *_l = NULL; } +int global_verbosity_level; //Necessary for hb_deep_log /********************************************************************** - * hb_log + * hb_valog ********************************************************************** * If verbose mode is one, print message with timestamp. Messages * longer than 180 characters are stripped ;p *********************************************************************/ -void hb_log( char * log, ... ) +void hb_valog( hb_debug_level_t level, const char * prefix, const char * log, va_list args) { char string[362]; /* 360 chars + \n + \0 */ time_t _now; struct tm * now; - va_list args; if( !getenv( "HB_DEBUG" ) ) { @@ -871,16 +871,30 @@ void hb_log( char * log, ... ) return; } + 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 ); + if ( prefix && *prefix ) + { + // limit the prefix length + snprintf( string, 40, "[%02d:%02d:%02d] %s ", + now->tm_hour, now->tm_min, now->tm_sec, prefix ); + } + else + { + sprintf( string, "[%02d:%02d:%02d] ", + now->tm_hour, now->tm_min, now->tm_sec ); + } + int end = strlen( string ); /* Convert the message to a string */ - va_start( args, log ); - vsnprintf( string + 11, 349, log, args ); - va_end( args ); + vsnprintf( string + end, 361 - end, log, args ); /* Add the end of line */ strcat( string, "\n" ); @@ -889,7 +903,21 @@ void hb_log( char * log, ... ) fprintf( stderr, "%s", string ); } -int global_verbosity_level; //Necessary for hb_deep_log +/********************************************************************** + * hb_log + ********************************************************************** + * If verbose mode is one, print message with timestamp. Messages + * longer than 180 characters are stripped ;p + *********************************************************************/ +void hb_log( char * log, ... ) +{ + va_list args; + + va_start( args, log ); + hb_valog( 0, NULL, log, args ); + va_end( args ); +} + /********************************************************************** * hb_deep_log ********************************************************************** @@ -898,33 +926,11 @@ int global_verbosity_level; //Necessary for hb_deep_log *********************************************************************/ 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 ); + hb_valog( level, NULL, log, args ); va_end( args ); - - /* Add the end of line */ - strcat( string, "\n" ); - - /* Print it */ - fprintf( stderr, "%s", string ); } /********************************************************************** diff --git a/libhb/decssasub.c b/libhb/decssasub.c index 460a8ddc0..2d2ec3d2b 100644 --- a/libhb/decssasub.c +++ b/libhb/decssasub.c @@ -19,7 +19,6 @@ * * @author David Foster (davidfstr) */ - #include <stdlib.h> #include <stdio.h> #include "hb.h" @@ -574,15 +573,7 @@ static void ssa_log(int level, const char *fmt, va_list args, void *data) { if ( level < 5 ) // same as default verbosity when no callback is set { - char *msg; - if ( vasprintf( &msg, fmt, args ) < 0 ) - { - hb_log( "decssasub: could not report libass message\n" ); - return; - } - hb_log( "[ass] %s", msg ); // no need for extra '\n' because libass sends it - - free( msg ); + hb_valog( 1, "[ass]", fmt, args ); } } diff --git a/libhb/internal.h b/libhb/internal.h index f92ce263a..b78072ad8 100644 --- a/libhb/internal.h +++ b/libhb/internal.h @@ -15,6 +15,7 @@ typedef enum hb_debug_level_s HB_HOUSEKEEPING_LOG = 2, // stuff we hate scrolling through HB_GRANULAR_LOG = 3 // sample-by-sample } hb_debug_level_t; +void hb_valog( hb_debug_level_t level, const char * prefix, const char * log, va_list args) HB_WPRINTF(3,0); void hb_deep_log( hb_debug_level_t level, char * log, ... ) HB_WPRINTF(2,3); void hb_error( char * fmt, ...) HB_WPRINTF(1,2); |