forked from avTranscoder/avTranscoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.cpp
More file actions
69 lines (58 loc) · 1.42 KB
/
Copy pathlog.cpp
File metadata and controls
69 lines (58 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "log.hpp"
namespace avtranscoder
{
void callbackToWriteInFile( void *ptr, int level, const char *fmt, va_list vl )
{
std::ofstream outputFile;
outputFile.open( LOG_FILE, std::ios::out | std::ios::app );
#ifdef AVTRANSCODER_FFMPEG_DEPENDENCY
// Format a line of log the same way as the default callback
char line[1024];
static int print_prefix = 1;
av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix); //only available with ffmpeg
outputFile << line;
#else
outputFile << "Warning: currently can't log in file with avtranscoder when depending on libav" << std::endl;
#endif
outputFile.close();
}
void Logger::setLogLevel( const int level )
{
av_log_set_level( level );
}
void Logger::log( const int level, const std::string& msg )
{
std::string avTranscoderMsg( "[avTranscoder - " );
std::string levelStr;
switch( level )
{
case AV_LOG_DEBUG:
levelStr = "debug";
break;
case AV_LOG_INFO:
levelStr = "info";
break;
case AV_LOG_WARNING:
levelStr = "warning";
break;
case AV_LOG_ERROR:
levelStr = "error";
break;
default:
break;
}
avTranscoderMsg += levelStr;
avTranscoderMsg += "] ";
avTranscoderMsg += msg;
avTranscoderMsg += "\n";
av_log( NULL, level, avTranscoderMsg.c_str() );
}
void Logger::logInFile()
{
av_log_set_callback( callbackToWriteInFile );
// clean log file
std::ofstream outputFile;
outputFile.open( LOG_FILE );
outputFile.close();
}
}