AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
log.cpp
Go to the documentation of this file.
1 #include "log.hpp"
2 
3 namespace avtranscoder
4 {
5 
6 std::string Logger::logHeaderMessage = "";
7 
8 void callbackToWriteInFile(void* ptr, int level, const char* fmt, va_list vl)
9 {
10  std::ofstream outputFile;
11  outputFile.open(LOG_FILE, std::ios::out | std::ios::app);
12 
13 #ifdef AVTRANSCODER_FFMPEG_DEPENDENCY
14  // Format a line of log the same way as the default callback
15  char line[1024];
16  static int print_prefix = 1;
17  av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix); // only available with ffmpeg
18  outputFile << line;
19 #else
20  outputFile << "Warning: currently can't log in file with avtranscoder when depending on libav" << std::endl;
21 #endif
22 
23  outputFile.close();
24 }
25 
26 void Logger::setLogLevel(const int level)
27 {
28  av_log_set_level(level);
29 }
30 
31 void Logger::log(const int level, const std::string& msg)
32 {
33  // add header message
34  std::string levelStr;
35  switch(level)
36  {
37  case AV_LOG_DEBUG:
38  levelStr = "debug";
39  break;
40  case AV_LOG_INFO:
41  levelStr = "info";
42  break;
43  case AV_LOG_WARNING:
44  levelStr = "warning";
45  break;
46  case AV_LOG_ERROR:
47  levelStr = "error";
48  break;
49  default:
50  break;
51  }
52  std::string logMessage = "[avTranscoder - " + levelStr + "] ";
53 
54  // add content message
55  logMessage += msg;
56  logMessage += "\n";
57 
58  // send message
59  av_log(NULL, level, logMessage.c_str());
60 }
61 
63 {
64  av_log_set_callback(callbackToWriteInFile);
65 
66  // clean log file
67  std::ofstream outputFile;
68  outputFile.open(LOG_FILE);
69  outputFile.close();
70 }
71 }
void callbackToWriteInFile(void *ptr, int level, const char *fmt, va_list vl)
Definition: log.cpp:8
#define LOG_FILE
Definition: log.hpp:16
static void log(const int level, const std::string &msg)
Log with the ffmpeg/libav log system.
Definition: log.cpp:31
static std::string logHeaderMessage
First caracters present for each logging message.
Definition: log.hpp:69
static void logInFile()
Log ffmpeg/libav and avtranscoder informations in a text file.
Definition: log.cpp:62
static void setLogLevel(const int level)
Set the log level of ffmpeg/libav.
Definition: log.cpp:26
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy