Skip to content

log: add private attribute to set header of logs only once #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/AvTranscoder/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace avtranscoder
{

std::string Logger::logHeaderMessage = "";

void callbackToWriteInFile( void *ptr, int level, const char *fmt, va_list vl )
{
std::ofstream outputFile;
Expand All @@ -23,13 +25,10 @@ void callbackToWriteInFile( void *ptr, int level, const char *fmt, va_list vl )

void Logger::setLogLevel( const int level )
{
// set ffmpeg log level
av_log_set_level( level );
}

void Logger::log( const int level, const std::string& msg )
{
std::string avTranscoderMsg( "[avTranscoder - " );

// set avtranscoder header message
std::string levelStr;
switch( level )
{
Expand All @@ -48,12 +47,15 @@ void Logger::log( const int level, const std::string& msg )
default:
break;
}
Logger::logHeaderMessage = "[avTranscoder - " + levelStr + "] ";
}

avTranscoderMsg += levelStr;
avTranscoderMsg += "] ";
avTranscoderMsg += msg;
avTranscoderMsg += "\n";
av_log( NULL, level, avTranscoderMsg.c_str() );
void Logger::log( const int level, const std::string& msg )
{
std::string logMessage = Logger::logHeaderMessage;
logMessage += msg;
logMessage += "\n";
av_log( NULL, level, logMessage.c_str() );
}

void Logger::logInFile()
Expand Down
3 changes: 3 additions & 0 deletions src/AvTranscoder/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class AvExport Logger
* @note log filename is avtranscoder.log
*/
static void logInFile();

private:
static std::string logHeaderMessage; ///< First caracters present for each logging message
};

}
Expand Down