Skip to content

Commit 038078a

Browse files
author
Clement Champetier
committed
Log system: use marco instead of function to log several inputs inline
1 parent bb2e0a2 commit 038078a

File tree

16 files changed

+96
-211
lines changed

16 files changed

+96
-211
lines changed

src/AvTranscoder/Option.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,7 @@ void loadOptions( OptionMap& outOptions, void* av_class, int req_flags )
291291

292292
if( ! parentFound )
293293
{
294-
std::string msg( "Can't find a choice option for ");
295-
msg += itOption->getName();
296-
Logger::warn( msg );
294+
LOG_WARN( "Can't find a choice option for " << itOption->getName() )
297295
}
298296
}
299297
}

src/AvTranscoder/ProfileLoader.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void ProfileLoader::loadProfiles( const std::string& avProfilesPath )
6464
}
6565
catch( const std::exception& e )
6666
{
67-
Logger::warn( e.what() );
67+
LOG_WARN( e.what() )
6868
}
6969
}
7070
}
@@ -218,12 +218,7 @@ int getFilesInDir( const std::string& dir, std::vector< std::string >& files )
218218
struct dirent *dirp;
219219
if( ( dp = opendir( dir.c_str() ) ) == NULL )
220220
{
221-
std::string msg( "Can't get files in directory " );
222-
msg += dir;
223-
msg += " (";
224-
msg += errno;
225-
msg += ")";
226-
Logger::error( msg );
221+
LOG_ERROR( "Can't get files in directory " << dir << " (" << errno << ")" )
227222
return errno;
228223
}
229224

src/AvTranscoder/codec/ICodec.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void ICodec::setCodec( const ECodecType type, const AVCodecID codecId )
119119
{
120120
if( codecId == 0 )
121121
{
122-
Logger::warn( "Unsupported codec with id 0");
122+
LOG_WARN( "Unsupported codec with id 0")
123123
return;
124124
}
125125

src/AvTranscoder/common.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
extern "C" {
44
#include <libavformat/avformat.h>
5-
#include <libavutil/log.h>
65
}
76

87
namespace avtranscoder
@@ -18,26 +17,6 @@ void Logger::setLogLevel( const int level )
1817
av_log_set_level( level );
1918
}
2019

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-
4120
void Logger::log( int level, const std::string& levelStr, const std::string& msg )
4221
{
4322
std::string avTranscoderMsg( "[avTranscoder - " );

src/AvTranscoder/common.hpp

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

1718
#include <string>
1819
#include <cstring>
20+
#include <sstream>
1921

2022
#ifdef SWIG
2123
#define AvExport
@@ -57,6 +59,11 @@ typedef AVRational Rational;
5759
/// Register all the codecs and formats which are enabled at configuration time.
5860
void AvExport preloadCodecsAndFormats();
5961

62+
#define LOG_DEBUG( ... ) { std::stringstream os; os << __VA_ARGS__; Logger::log( AV_LOG_DEBUG, "debug", os.str() ); }
63+
#define LOG_INFO( ... ) { std::stringstream os; os << __VA_ARGS__; Logger::log( AV_LOG_INFO, "info", os.str() ); }
64+
#define LOG_WARN( ... ) { std::stringstream os; os << __VA_ARGS__; Logger::log( AV_LOG_WARNING, "warning", os.str() ); }
65+
#define LOG_ERROR( ... ) { std::stringstream os; os << __VA_ARGS__; Logger::log( AV_LOG_ERROR, "error", os.str() ); }
66+
6067
/// Logger class which contains static functions to use ffmpeg/libav log system
6168
class AvExport Logger
6269
{
@@ -68,18 +75,12 @@ class AvExport Logger
6875
*/
6976
static void setLogLevel( const int level );
7077

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:
78+
/**
79+
* @brief Log with the ffmpeg/libav log system
80+
* @note use define LOG_* to log at DEBUG/INFO/WARN/ERROR level
81+
* @param msg: the message will be prefixed by '[avTranscoder - <level>]'
82+
* @param msg: the message will be suffixed by '\n'
83+
*/
8384
static void log( int level, const std::string& levelStr, const std::string& msg );
8485
};
8586

src/AvTranscoder/decoder/AudioDecoder.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,7 @@ void AudioDecoder::setProfile( const ProfileLoader::Profile& profile )
168168
}
169169
catch( std::exception& e )
170170
{
171-
std::string msg( "AudioDecoder - can't set option " );
172-
msg += (*it).first;
173-
msg += " to ";
174-
msg += (*it).second;
175-
msg += ": ";
176-
msg += e.what();
177-
Logger::warn( msg );
171+
LOG_WARN( "AudioDecoder - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
178172
}
179173
}
180174
}

src/AvTranscoder/decoder/VideoDecoder.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,7 @@ void VideoDecoder::setProfile( const ProfileLoader::Profile& profile )
127127
}
128128
catch( std::exception& e )
129129
{
130-
std::string msg( "VideoDecoder - can't set option " );
131-
msg += (*it).first;
132-
msg += " to ";
133-
msg += (*it).second;
134-
msg += ": ";
135-
msg += e.what();
136-
Logger::warn( msg );
130+
LOG_WARN( "VideoDecoder - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
137131
}
138132
}
139133
}

src/AvTranscoder/encoder/AudioEncoder.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,7 @@ void AudioEncoder::setProfile( const ProfileLoader::Profile& profile, const Audi
186186
}
187187
catch( std::exception& e )
188188
{
189-
std::string msg( "AudioEncoder - can't set option " );
190-
msg += (*it).first;
191-
msg += " to ";
192-
msg += (*it).second;
193-
msg += ": ";
194-
msg += e.what();
195-
Logger::warn( msg );
189+
LOG_WARN( "AudioEncoder - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
196190
}
197191
}
198192
}

src/AvTranscoder/encoder/VideoEncoder.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,7 @@ void VideoEncoder::setProfile( const ProfileLoader::Profile& profile, const avtr
183183
}
184184
catch( std::exception& e )
185185
{
186-
std::string msg( "VideoEncoder - can't set option " );
187-
msg += (*it).first;
188-
msg += " to ";
189-
msg += (*it).second;
190-
msg += ": ";
191-
msg += e.what();
192-
Logger::warn( msg );
186+
LOG_WARN( "VideoEncoder - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
193187
}
194188
}
195189
}

src/AvTranscoder/file/FormatContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void FormatContext::addMetaData( const std::string& key, const std::string& valu
126126
{
127127
char err[AV_ERROR_MAX_STRING_SIZE];
128128
av_strerror( ret, err, sizeof(err) );
129-
Logger::error( err );
129+
LOG_ERROR( err )
130130
}
131131
}
132132

src/AvTranscoder/file/InputFile.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,7 @@ void InputFile::seek( uint64_t position )
160160

161161
if( av_seek_frame( &_formatContext.getAVFormatContext(), -1, position, AVSEEK_FLAG_BACKWARD ) < 0 )
162162
{
163-
std::stringstream os;
164-
os << "Error when seek at ";
165-
os << position;
166-
os << " (in AV_TIME_BASE units) in file";
167-
Logger::error( os.str() );;
163+
LOG_ERROR( "Error when seek at " << position << " (in AV_TIME_BASE units) in file" )
168164
}
169165

170166
for( std::vector<InputStream*>::iterator it = _inputStreams.begin(); it != _inputStreams.end(); ++it )
@@ -218,13 +214,7 @@ void InputFile::setProfile( const ProfileLoader::Profile& profile )
218214
}
219215
catch( std::exception& e )
220216
{
221-
std::string msg( "InputFile - can't set option " );
222-
msg += (*it).first;
223-
msg += " to ";
224-
msg += (*it).second;
225-
msg += ": ";
226-
msg += e.what();
227-
Logger::warn( msg );
217+
LOG_WARN( "InputFile - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
228218
}
229219
}
230220
}

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ IOutputStream::EWrappingStatus OutputFile::wrap( const CodedData& data, const si
9999
if( ! data.getSize() )
100100
return IOutputStream::eWrappingSuccess;
101101

102-
std::stringstream os;
103-
os << "Wrap on stream " << streamId << " (" << data.getSize() << " bytes for frame " << _frameCount.at( streamId ) << ")";
104-
Logger::debug( os.str() );
102+
LOG_DEBUG( "Wrap on stream " << streamId << " (" << data.getSize() << " bytes for frame " << _frameCount.at( streamId ) << ")" )
105103

106104
AVPacket packet;
107105
av_init_packet( &packet );
@@ -179,13 +177,7 @@ void OutputFile::setProfile( const ProfileLoader::Profile& profile )
179177
}
180178
catch( std::exception& e )
181179
{
182-
std::string msg( "OutputFile - can't set option " );
183-
msg += (*it).first;
184-
msg += " to ";
185-
msg += (*it).second;
186-
msg += ": ";
187-
msg += e.what();
188-
Logger::warn( msg );
180+
LOG_WARN( "OutputFile - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
189181
}
190182
}
191183
}

src/AvTranscoder/mediaProperty/DataProperties.cpp

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -54,55 +54,53 @@ void DataProperties::detectAncillaryData()
5454
{
5555
if( pkt.stream_index == (int)_streamIndex )
5656
{
57-
Logger::debug( "DataProperties - start detect packet" );
57+
LOG_DEBUG( "DataProperties - start detect packet" );
5858

5959
size_t offset = 0;
60-
std::stringstream os;
61-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
62-
Logger::debug( os.str() ); os.str( "" );
63-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
64-
Logger::debug( os.str() ); os.str( "" );
65-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
66-
Logger::debug( os.str() ); os.str( "" );
67-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
68-
Logger::debug( os.str() ); os.str( "" );
69-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
70-
Logger::debug( os.str() ); os.str( "" );
71-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
72-
Logger::debug( os.str() ); os.str( "" );
73-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
74-
Logger::debug( os.str() ); os.str( "" );
75-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
76-
Logger::debug( os.str() ); os.str( "" );
77-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
78-
Logger::debug( os.str() ); os.str( "" );
79-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
80-
Logger::debug( os.str() ); os.str( "" );
81-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
82-
Logger::debug( os.str() ); os.str( "" );
83-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
84-
Logger::debug( os.str() ); os.str( "" );
85-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
86-
Logger::debug( os.str() ); os.str( "" );
87-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
88-
Logger::debug( os.str() ); os.str( "" );
89-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
90-
Logger::debug( os.str() ); os.str( "" );
91-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
92-
Logger::debug( os.str() ); os.str( "" );
93-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
94-
Logger::debug( os.str() ); os.str( "" );
95-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
96-
Logger::debug( os.str() ); os.str( "" );
97-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
98-
Logger::debug( os.str() ); os.str( "" );
99-
os << offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ); offset++;
100-
Logger::debug( os.str() ); os.str( "" );
60+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
61+
offset++;
62+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
63+
offset++;
64+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
65+
offset++;
66+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
67+
offset++;
68+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
69+
offset++;
70+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
71+
offset++;
72+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
73+
offset++;
74+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
75+
offset++;
76+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
77+
offset++;
78+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
79+
offset++;
80+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
81+
offset++;
82+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
83+
offset++;
84+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
85+
offset++;
86+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
87+
offset++;
88+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
89+
offset++;
90+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
91+
offset++;
92+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
93+
offset++;
94+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
95+
offset++;
96+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
97+
offset++;
98+
LOG_DEBUG( offset << " - " << (int) pkt.data[ offset ] << " | " << std::bitset<8>( pkt.data[ offset ] ) )
99+
offset++;
101100

102101
unsigned short numberOfLines = (unsigned int) ( pkt.data[0] << 8 ) + pkt.data[1];
103102

104-
os << "DataProperties - number of lines " << numberOfLines;
105-
Logger::debug( os.str() );
103+
LOG_DEBUG( "DataProperties - number of lines " << numberOfLines )
106104

107105
detection = true;
108106
}

0 commit comments

Comments
 (0)