Skip to content

Commit 7a648e3

Browse files
author
Clement Champetier
committed
common: add log functions to use ffmpeg/libav log system
* Functions are encapsulate in Logger class. * Fix #100
1 parent d7b0296 commit 7a648e3

File tree

4 files changed

+60
-11
lines changed

4 files changed

+60
-11
lines changed

app/avProcessor/avProcessor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ int main( int argc, char** argv )
140140
return( -1 );
141141
}
142142

143-
avtranscoder::setLogLevel( AV_LOG_QUIET );
143+
avtranscoder::Logger::setLogLevel( AV_LOG_QUIET );
144144
if( verbose )
145-
avtranscoder::setLogLevel( AV_LOG_DEBUG );
145+
avtranscoder::Logger::setLogLevel( AV_LOG_DEBUG );
146146

147147
try
148148
{

app/avThumbnail/avThumbnail.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int main( int argc, char** argv )
5454
return( -1 );
5555
}
5656

57-
avtranscoder::setLogLevel( AV_LOG_QUIET );
57+
avtranscoder::Logger::setLogLevel( AV_LOG_QUIET );
5858
avtranscoder::preloadCodecsAndFormats();
5959

6060
// input file

src/AvTranscoder/common.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
extern "C" {
44
#include <libavformat/avformat.h>
5+
#include <libavutil/log.h>
56
}
67

78
namespace avtranscoder
@@ -12,9 +13,39 @@ void preloadCodecsAndFormats()
1213
av_register_all();
1314
}
1415

15-
void setLogLevel( const int level )
16+
void Logger::setLogLevel( const int level )
1617
{
1718
av_log_set_level( level );
1819
}
1920

21+
void Logger::debug( const std::string msg )
22+
{
23+
log( AV_LOG_DEBUG, "debug", msg );
24+
}
25+
26+
void Logger::info( const std::string msg )
27+
{
28+
log( AV_LOG_INFO, "info", msg );
29+
}
30+
31+
void Logger::warn( const std::string msg )
32+
{
33+
log( AV_LOG_WARNING, "warning", msg );
34+
}
35+
36+
void Logger::error( const std::string msg )
37+
{
38+
log( AV_LOG_ERROR, "error", msg );
39+
}
40+
41+
void Logger::log( int level, const std::string& levelStr, const std::string& msg )
42+
{
43+
std::string avTranscoderMsg( "[avTranscoder - " );
44+
avTranscoderMsg += levelStr;
45+
avTranscoderMsg += "] ";
46+
avTranscoderMsg += msg;
47+
avTranscoderMsg += "\n";
48+
av_log( NULL, level, avTranscoderMsg.c_str() );
49+
}
50+
2051
}

src/AvTranscoder/common.hpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ extern "C" {
1212
#include <libavcodec/version.h>
1313
#include <libavutil/error.h>
1414
#include <libavutil/rational.h>
15-
#include <libavutil/log.h>
1615
}
1716

1817
#include <string>
@@ -58,12 +57,31 @@ typedef AVRational Rational;
5857
/// Register all the codecs and formats which are enabled at configuration time.
5958
void AvExport preloadCodecsAndFormats();
6059

61-
/**
62-
* @brief Set the log level of ffmpeg/libav.
63-
* @param level: refer to define AV_LOG_xxx (from AV_LOG_QUIET to AV_LOG_DEBUG)
64-
* @see SWIG interface avLogLevel.i
65-
*/
66-
void AvExport setLogLevel( const int level );
60+
/// Logger class which contains static functions to use ffmpeg/libav log system
61+
class AvExport Logger
62+
{
63+
public:
64+
/**
65+
* @brief Set the log level of ffmpeg/libav.
66+
* @param level: refer to define AV_LOG_xxx (from AV_LOG_QUIET to AV_LOG_DEBUG)
67+
* @see SWIG interface avLogLevel.i
68+
*/
69+
static void setLogLevel( const int level );
70+
71+
///@{
72+
/// @brief Log with the ffmpeg/libav log system
73+
/// @note use shortcuts to log at debug/info/warning/error level
74+
/// @param msg: the message will be prefix by '[avTranscoder - <level>]'
75+
///
76+
static void debug( const std::string msg );
77+
static void info( const std::string msg );
78+
static void warn( const std::string msg );
79+
static void error( const std::string msg );
80+
///@}
81+
82+
private:
83+
static void log( int level, const std::string& levelStr, const std::string& msg );
84+
};
6785

6886
}
6987

0 commit comments

Comments
 (0)