summaryrefslogtreecommitdiffstats
path: root/libhb/common.c
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2011-06-15 16:38:13 +0000
committerjstebbins <[email protected]>2011-06-15 16:38:13 +0000
commit4d7216fba8652a83821be49cd16cc851b5cc4cd2 (patch)
treee809a93e3606ebc118f12e75b88fc15fced54bcb /libhb/common.c
parent74dd3640936fe30a7be562615a997c30ebe5acb0 (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
Diffstat (limited to 'libhb/common.c')
-rw-r--r--libhb/common.c70
1 files changed, 38 insertions, 32 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 );
}
/**********************************************************************